@hara-lang/native-browser 0.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,101 @@
1
+ # @hara-lang/native-browser
2
+
3
+ Embeddable Hara runtime for browsers and CDN scripts.
4
+
5
+ ```js
6
+ import { start } from "@hara-lang/native-browser/vm";
7
+
8
+ const hara = await start();
9
+ console.log(hara.eval("(+ 19 23)"));
10
+ ```
11
+
12
+ The package root remains an alias for `/vm`. Heavy-duty whole-function
13
+ WebAssembly compilation is available from `@hara-lang/native-browser/full`. The
14
+ compiler runs inside the browser runtime and the resulting module executes on
15
+ the browser's own WebAssembly engine:
16
+
17
+ ```js
18
+ import { start } from "@hara-lang/native-browser/full";
19
+ const hara = await start();
20
+ const compiled = await hara.compileWholeWasm(
21
+ "(loop [i 0 acc 0] (if (< i 5000) (recur (+ i 1) (+ acc i)) acc))"
22
+ );
23
+ console.log(compiled.call()); // 12497500n
24
+ ```
25
+
26
+ The full package owns dynamic constants and persistent values in the outer Hara
27
+ runtime while generated scalar and specialized collection work runs directly
28
+ inside the browser's WebAssembly engine.
29
+
30
+ The release also provides an IIFE bundle for a plain script tag:
31
+
32
+ ```html
33
+ <script src="https://unpkg.com/@hara-lang/native-browser@0.1.9/dist/native-vm/hara.js"></script>
34
+ <script>
35
+ Hara.start().then((hara) => console.log(hara.eval("(+ 19 23)")));
36
+ </script>
37
+ ```
38
+
39
+ The default browser runtime is the small core evaluator. Foundation and other
40
+ semantic package families are opt-in, so a page can choose the exact lock and
41
+ load only the capabilities it needs. Host resources can still be registered
42
+ before requiring them:
43
+
44
+ ```js
45
+ const hara = await Hara.start({
46
+ resources: {
47
+ "app.config": "(ns app.config) (def answer 42)"
48
+ }
49
+ });
50
+ ```
51
+
52
+ Locked Hara packages can be fetched from an immutable package host (including
53
+ `packages.*`) or a release asset and installed before application evaluation:
54
+
55
+ ```js
56
+ import { installLockedPackages, start } from "@hara-lang/native-browser";
57
+
58
+ const hara = await start();
59
+ const lock = await fetch(projectLockUrl).then((response) => response.text());
60
+ await installLockedPackages(hara, lock);
61
+ hara.require("my.world");
62
+ ```
63
+
64
+ The same selection can happen during isolated startup. `targets` accepts a
65
+ semantic package name, an exact lock coordinate, or a namespace:
66
+
67
+ ```js
68
+ const hara = await start({
69
+ lock,
70
+ targets: ["lang.model.v1.postgres"],
71
+ packageOptions: { origin: "https://packages.example" }
72
+ });
73
+ ```
74
+
75
+ HARP archives may contain a verified `bytecode/package.hbx`. The loader checks
76
+ its manifest digest and installs the HBX0 index when the VM runtime exposes the
77
+ bundle seam; otherwise the verified HAL resources remain the source fallback.
78
+ Package selection is described by the package's signed lock. The source package
79
+ defines semantic profiles and dependency conventions; this host only verifies
80
+ and activates the selected archive set.
81
+
82
+ Memory-backed Wasm packages use the explicit `memory.v1` binding route. The
83
+ manifest, canonical interface, and canonical `bindings.edn` plan are verified
84
+ before the module is instantiated:
85
+
86
+ ```js
87
+ hara.installMemoryWasmBinding(manifest, interfaceSource, bindingsSource, wasmBytes);
88
+ hara.require("my.wasm.package");
89
+ ```
90
+
91
+ Only format-2 locks are accepted. The loader verifies the HARP archive digest,
92
+ optional archive size, every file declared by `package.edn`, safe archive paths,
93
+ and unique HAL namespaces. Resources are registered only after the complete
94
+ lock has passed verification. A lock entry may use `:distribution/url`,
95
+ `:packages/url`, `:release-url`, or `:url`; package distribution URLs take
96
+ precedence and the lock digest remains authoritative.
97
+
98
+ Verified `:hta` extensions select only their prebuilt `:browser` web-worker
99
+ target. Declared assets are loaded from the archive, and unsupported
100
+ capabilities fail during installation; no Cargo, Maven, or compiler step is
101
+ performed.
@@ -0,0 +1,88 @@
1
+ export interface StartOptions {
2
+ /** Override the default adjacent hara_wasm_bg.wasm URL. */
3
+ wasmUrl?: RequestInfo | URL | ArrayBuffer | WebAssembly.Module | Uint8Array;
4
+ /** Host resources registered before the first require. */
5
+ resources?: Map<string, string> | Record<string, string>;
6
+ /** Exact lock used to install semantic packages before the runtime is returned. */
7
+ lock?: string;
8
+ /** Semantic package names, coordinates, or namespaces selected from the lock. */
9
+ targets?: string[];
10
+ /** Fetch, capability, host, and browser-worker policy for package installation. */
11
+ packageOptions?: LockedPackageOptions;
12
+ }
13
+
14
+ export interface HaraRuntime {
15
+ eval(source: string): string;
16
+ require(namespace: string): string;
17
+ registerResource(namespace: string, source: string): void;
18
+ installDirectWasmImport(logical: string, bytes: Uint8Array): void;
19
+ installMemoryWasmBinding(
20
+ manifest: string,
21
+ interfaceSource: string,
22
+ bindingsSource: string,
23
+ bytes: Uint8Array
24
+ ): void;
25
+ unregisterResource(namespace: string): void;
26
+ evalInNamespace(namespace: string, source: string): string;
27
+ currentNamespace(): string;
28
+ compileBytecode(source: string): Uint8Array;
29
+ evalBytecode(artifact: Uint8Array): string;
30
+ evalBytecodeBundle(artifact: Uint8Array): void;
31
+ installPackages(lockSource: string, options?: LockedPackageOptions): Promise<string[]>;
32
+ compileWholeWasm(source: string): Promise<WholeWasmModule>;
33
+ compileWholeWasmProduct(source: string): WholeWasmProduct;
34
+ loadWholeWasm(
35
+ product: WholeWasmProduct | Uint8Array | ArrayBuffer
36
+ ): Promise<WholeWasmModule>;
37
+ installHostHandler(handler: Function): void;
38
+ dispose(): Promise<void>;
39
+ readonly raw: unknown;
40
+ }
41
+
42
+ export interface WholeWasmModule {
43
+ call(...arguments: Array<number | bigint>): bigint;
44
+ callFunction(functionId: number, ...arguments: Array<number | bigint>): bigint;
45
+ readonly manifest: Readonly<Record<string, unknown>> | null;
46
+ readonly module: WebAssembly.Module;
47
+ readonly instance: WebAssembly.Instance;
48
+ }
49
+
50
+ export interface WholeWasmProduct {
51
+ readonly artifact: Uint8Array;
52
+ readonly manifest: Readonly<Record<string, unknown>>;
53
+ }
54
+
55
+ export interface LockedPackageOptions {
56
+ fetch?: typeof globalThis.fetch;
57
+ origin?: string;
58
+ targets?: string[];
59
+ capabilities?: string[];
60
+ hostCalls?: Record<string, Function | Record<string, Function>>;
61
+ workerFactory?: (url: string, options: WorkerOptions) => Worker;
62
+ createObjectURL?: (blob: Blob) => string;
63
+ revokeObjectURL?: (url: string) => void;
64
+ Blob?: typeof Blob;
65
+ }
66
+
67
+ export function loadLockedPackageResources(
68
+ lockSource: string,
69
+ request?: typeof globalThis.fetch
70
+ ): Promise<Record<string, string>>;
71
+
72
+ export function installLockedPackages(
73
+ runtime: Pick<HaraRuntime, "registerResource"> & Partial<Pick<HaraRuntime, "evalBytecodeBundle">>,
74
+ lockSource: string,
75
+ options?: LockedPackageOptions
76
+ ): Promise<string[]>;
77
+
78
+ export function installPackageProvider(
79
+ runtime: HaraRuntime,
80
+ lockSource: string,
81
+ options?: LockedPackageOptions
82
+ ): { readonly active: ReadonlySet<string>; readonly handler: Function };
83
+
84
+ export function disposeBrowserPackageProviders(runtime: HaraRuntime): Promise<void>;
85
+
86
+ export function start(options?: StartOptions): Promise<HaraRuntime>;
87
+ export const ready: Promise<HaraRuntime>;
88
+ export default start;