Improve JSR package metadata
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
/**
|
||||
* Browser and JavaScript runtime bindings for the Decodal evaluator.
|
||||
*
|
||||
* This module wraps the wasm-bindgen output generated from the Rust
|
||||
* `decodal-wasm` crate and exposes stable, documented entrypoints for JSR
|
||||
* users. The exported evaluator functions return JSON strings.
|
||||
*
|
||||
* @module
|
||||
*/
|
||||
import initWasm, {
|
||||
evaluate as evaluateImpl,
|
||||
evaluateProject as evaluateProjectImpl,
|
||||
initSync as initSyncImpl,
|
||||
} from './decodal_wasm.js';
|
||||
|
||||
/** Input accepted by the wasm-bindgen initializer. */
|
||||
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
||||
|
||||
/** Initialized Decodal WebAssembly exports. */
|
||||
export interface InitOutput {
|
||||
/** Linear memory exported by the WebAssembly module. */
|
||||
readonly memory: WebAssembly.Memory;
|
||||
readonly evaluate: (source: number, len: number) => [number, number, number, number];
|
||||
readonly evaluateProject: (entry: number, entryLen: number, files: number, filesLen: number) => [number, number, number, number];
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the Decodal WebAssembly runtime asynchronously.
|
||||
*
|
||||
* @param moduleOrPath - Optional WebAssembly module, bytes, response, URL, or request.
|
||||
* @returns The initialized WebAssembly exports.
|
||||
*/
|
||||
export default async function initDecodalRuntime(moduleOrPath?: InitInput): Promise<InitOutput> {
|
||||
return await initWasm(moduleOrPath) as InitOutput;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the Decodal WebAssembly runtime synchronously.
|
||||
*
|
||||
* @param module - Compiled module, bytes, or wasm-bindgen sync initialization input.
|
||||
* @returns The initialized WebAssembly exports.
|
||||
*/
|
||||
export function initSync(module: WebAssembly.Module | BufferSource): InitOutput {
|
||||
return initSyncImpl(module) as InitOutput;
|
||||
}
|
||||
|
||||
/**
|
||||
* Evaluate and materialize a single Decodal source string.
|
||||
*
|
||||
* @param source - Decodal source text.
|
||||
* @returns A JSON string containing either `{ ok: true, output }` or `{ ok: false, error }`.
|
||||
*/
|
||||
export function evaluate(source: string): string {
|
||||
return evaluateImpl(source);
|
||||
}
|
||||
|
||||
/**
|
||||
* Evaluate and materialize a virtual multi-file Decodal project.
|
||||
*
|
||||
* @param entry - Entry point file path to materialize.
|
||||
* @param filesJson - JSON object mapping virtual file paths to source strings.
|
||||
* @returns A JSON string containing either `{ ok: true, output }` or `{ ok: false, error }`.
|
||||
*/
|
||||
export function evaluateProject(entry: string, filesJson: string): string {
|
||||
return evaluateProjectImpl(entry, filesJson);
|
||||
}
|
||||
Reference in New Issue
Block a user