.. _dip-web: WebAssembly and JavaScript ========================== ``loadDIPL`` parses text and projects and exposes the inspection model. Basic examples -------------- After building the web module, parse text and inspect a value: .. code-block:: javascript import { loadDIPL } from "./bindings/web/index.mjs"; const dipl = await loadDIPL(); const model = dipl.parse("distance float = 24 m"); console.log(model.describe("distance").valueText); // 24 model.dispose(); Evaluate a replacement input without changing the original model: .. code-block:: javascript import { loadDIPL } from "./bindings/web/index.mjs"; const dipl = await loadDIPL(); const model = dipl.parse("steps int = 100"); const candidate = model.withOverride("steps = 200"); console.log(candidate.describe("steps").valueText); // 200 candidate.dispose(); model.dispose(); Common workflows ---------------- .. list-table:: :header-rows: 1 * - Task - Call chain - Result * - Initialize DIPL - ``await loadDIPL()`` - Runtime object * - Parse text - ``dipl.parse(source)`` - ``DIPLModel`` * - Parse project input - ``dipl.parseProject(project)``; ``dipl.parseBundle(bundle)`` - ``DIPLModel`` * - Discover paths - ``model.paths()`` - ``string[]`` * - Describe values - ``model.describe(path)``; ``model.describeMany(paths)`` - ``Description``; ``Description[]`` * - Inspect schemas - ``model.schemas()`` - ``SchemaHierarchy`` * - Reevaluate an override - ``model.withOverride(body)`` - New ``DIPLModel`` * - Validate without evaluating - ``dipl.validate``, ``validateProject``, or ``validateBundle`` - ``Validation`` with optional ``diagnostic`` * - Release a model - ``model.dispose()`` - No result .. code-block:: javascript import { loadDIPL } from "./bindings/web/index.mjs"; const dipl = await loadDIPL(); // runtime object const source = ` distance float = 24 m duration float = 8 s speed float = ({?distance} / {?duration}) m/s`; const model = dipl.parse(source); // DIPLModel console.log(model.paths()); // string[] console.log(model.describeMany(["distance", "speed"])); const candidate = model.withOverride("distance = 32 m"); console.log(candidate.describe("speed").valueText); // string | null const validation = dipl.validate(source, "missing = 1"); if (!validation.valid && validation.diagnostic) { console.error(validation.diagnostic.message, validation.diagnostic.details, validation.diagnostic.suggestion); } candidate.dispose(); model.dispose(); ``withOverride`` creates a separate evaluated model and does not mutate the original. Dispose every model; validation results contain plain records and need no cleanup. See the :doc:`WebAssembly guide <../../../integrations/web>` for project bundles, overrides, and schema inspection, and :doc:`DIP inspection <../inspection>` for the related native API. **DIPL developer tools.** The web binding provides ``validate()``, ``validateProject()``, and ``validateBundle()`` with structured diagnostics. It does not expose the formatter or linter. Use the CLI or C++ tools for formatting and linting; see the :doc:`DIPL developer tools <../../../integrations/devtools>` page. Current limitations and differences ----------------------------------- Compared with the canonical C++ implementation: - Inputs are text or supplied project bundles. The binding does not open arbitrary host files or load/save DIPH5 archives. - Results are bounded JavaScript descriptions rather than native Environment and Cursor objects. ``withOverride()`` creates a separate model; it does not write source files. Release each model with ``dispose()``. - Native adapters, exports, reports, snapshot comparison, editing/setup sessions, and experiment recording are not exposed. - ``validate()``, ``validateProject()``, and ``validateBundle()`` are available. The formatter and linter are not; use the CLI or C++ tooling API. Binding reference ----------------- This is a lookup index, not a sequence to read from top to bottom. Use `Common workflows` above to choose a task, then find the exact JavaScript name below. Methods are shown with parentheses; properties and option fields are shown without them. The TypeScript declarations are the complete source for input and result shapes. Load and evaluate ~~~~~~~~~~~~~~~~~ - ``loadDIPL(options?)``. - ``dipl.parse(source)``, ``dipl.parseProject(project)``, and ``dipl.parseBundle(bundle)``. - ``dipl.validate(source, overrideBody?)``, ``dipl.validateProject(project, overrideBody?)``, and ``dipl.validateBundle(bundle, overrideBody?)``. Model inspection and previews ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ``model.paths()``. - ``model.describe(path, maxValueElements=16)`` and ``model.describeMany(paths, maxValueElements=16)``. - ``model.schemas()`` and ``model.withOverride(body)``. - ``model.dispose()`` after the model is no longer needed. Input and result types ~~~~~~~~~~~~~~~~~~~~~~ - ``ProjectInput`` fields ``units``, ``schemas``, ``code``, and ``overrides``; each entry is ``{name, text}``. - ``ProjectBundle`` with ``format``, ``entry``, and ``{path, text}`` files. - ``Description``, ``Metadata``, ``SchemaHierarchy``, ``Validation``, ``Diagnostic``, and ``SourceLocation``.