@sanbus/galley-wasm 0.0.1

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/src/index.ts ADDED
@@ -0,0 +1,82 @@
1
+ /**
2
+ * Galley JavaScript bindings over WebAssembly — public surface.
3
+ *
4
+ * Binds the runtime-neutral `@sanbus/galley-core` to the wasm port. Mirrors the
5
+ * layout of the Node adapter and the C header `bindings/c/galley.h`.
6
+ *
7
+ * Initialization: `await init()` (required in browsers; optional under Node
8
+ * where the module auto-initializes synchronously on first use).
9
+ */
10
+
11
+ import { getWasmPort, findLibrary, init, initSync, seedDefault, NeedInitError } from "./ffi.ts";
12
+ import { Session } from "./session.ts";
13
+
14
+ // Core surface (Session base is shadowed by the adapter subclass below).
15
+ export * from "@sanbus/galley-core";
16
+ export { Session };
17
+ export { findLibrary, init, initSync, seedDefault, NeedInitError };
18
+ export { getWasmPort, wasmFileName } from "./ffi.ts";
19
+ export type { InitOptions } from "./ffi.ts";
20
+ export type { SessionOptions, WalkStep, Diagnostic, TreeSnapshot } from "@sanbus/galley-core";
21
+
22
+ // Module-level queries (mirror galley.h)
23
+ export function version(): string {
24
+ return getWasmPort().version();
25
+ }
26
+
27
+ export function parserType(): number {
28
+ return getWasmPort().parserType();
29
+ }
30
+
31
+ export function errorRecoveryMode(): number {
32
+ return getWasmPort().errorRecoveryMode();
33
+ }
34
+
35
+ export function hasAst(): boolean {
36
+ return getWasmPort().hasAst();
37
+ }
38
+
39
+ export function hasProcedures(): boolean {
40
+ return getWasmPort().hasProcedures();
41
+ }
42
+
43
+ export function allowsNoAstTreeProcedures(): boolean {
44
+ return getWasmPort().allowsNoAstTreeProcedures();
45
+ }
46
+
47
+ export function sourceRetentionEnabled(): boolean {
48
+ return getWasmPort().sourceRetentionEnabled();
49
+ }
50
+
51
+ export function hasPositionTracking(): boolean {
52
+ return getWasmPort().hasPositionTracking();
53
+ }
54
+
55
+ export function hasInputStreaming(): boolean {
56
+ return getWasmPort().hasInputStreaming();
57
+ }
58
+
59
+ export function usesVerbatim(): boolean {
60
+ return getWasmPort().usesVerbatim();
61
+ }
62
+
63
+ export function stackOverflowRecoveryAvailable(): boolean {
64
+ return getWasmPort().stackOverflowRecoveryAvailable();
65
+ }
66
+
67
+ export function symbolCount(): number {
68
+ return getWasmPort().symbolCount();
69
+ }
70
+
71
+ export function variableCount(): number {
72
+ return getWasmPort().variableCount();
73
+ }
74
+
75
+ export function statusString(status: number): string | null {
76
+ return getWasmPort().statusString(status);
77
+ }
78
+
79
+ // Preserve original Python naming aliases for docs parity
80
+ export const has_ast = hasAst;
81
+ export const has_procedures = hasProcedures;
82
+ export const has_position_tracking = hasPositionTracking;
package/src/session.ts ADDED
@@ -0,0 +1,26 @@
1
+ /**
2
+ * WebAssembly `Session`: the core session bound to the wasm port.
3
+ *
4
+ * Runs the adapter auto-scan for host procedures (a no-op outside Node or
5
+ * when hooks are already registered); the guest import itself is always
6
+ * wired at instantiation.
7
+ */
8
+
9
+ import { Session as CoreSession } from "@sanbus/galley-core";
10
+ import type { SessionOptions } from "@sanbus/galley-core";
11
+ import { getWasmPort } from "./ffi.ts";
12
+ import { ensureDispatch } from "./dispatch.ts";
13
+
14
+ export type { SessionOptions };
15
+
16
+ export class Session extends CoreSession {
17
+ constructor(options: SessionOptions = {}) {
18
+ const port = getWasmPort(options.libraryPath);
19
+ try {
20
+ ensureDispatch(options.libraryPath ?? port.libraryPath);
21
+ } catch {
22
+ // auto-scan is best-effort; explicit installProcedures always works.
23
+ }
24
+ super(port, options);
25
+ }
26
+ }