@pipelex/tools-wasm 0.1.0
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 +52 -0
- package/dist/index.d.ts +63 -0
- package/dist/index.js +2 -0
- package/package.json +37 -0
package/README.md
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# @pipelex/tools-wasm
|
|
2
|
+
|
|
3
|
+
MTHDS lint & format compiled to WebAssembly — a lean, fully offline binding over the shared Rust engine that also powers the `plxt` CLI, the `pipelex-tools-py` Python library, and the Pipelex API's `/v1/lint` + `/v1/format`. All bindings emit the identical `Diagnostic` wire shape by construction.
|
|
4
|
+
|
|
5
|
+
- **Offline by design:** lint validates against the MTHDS JSON Schema embedded at build time — no HTTP, no filesystem, no config discovery. The schema therefore freezes at package build time; server-side `validate` remains the authoritative verdict on skew.
|
|
6
|
+
- **Lean:** unlike `@pipelex/lsp` (which carries the whole language server), this package exposes only `lintMthds` and `formatMthds`, small enough to vendor inside a plugin hook bundle.
|
|
7
|
+
|
|
8
|
+
## Usage
|
|
9
|
+
|
|
10
|
+
The package ships a single UMD bundle (like its `@taplo/lib` / `@pipelex/lsp` siblings), so pick the import form for your environment:
|
|
11
|
+
|
|
12
|
+
```js
|
|
13
|
+
// Bundlers (esbuild, rollup, webpack, vite) — the primary use-case of
|
|
14
|
+
// vendoring into a plugin hook bundle — resolve named imports from UMD:
|
|
15
|
+
import { initialize, lintMthds, formatMthds } from "@pipelex/tools-wasm";
|
|
16
|
+
|
|
17
|
+
// Native Node ESM cannot see named exports through the minified UMD wrapper;
|
|
18
|
+
// default-import and destructure instead:
|
|
19
|
+
import pkg from "@pipelex/tools-wasm";
|
|
20
|
+
const { initialize, lintMthds, formatMthds } = pkg;
|
|
21
|
+
|
|
22
|
+
// CommonJS:
|
|
23
|
+
const { initialize, lintMthds, formatMthds } = require("@pipelex/tools-wasm");
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
```js
|
|
27
|
+
// Once, at startup (loads the WASM module).
|
|
28
|
+
await initialize();
|
|
29
|
+
|
|
30
|
+
// Lint: syntax → semantic → schema, short-circuiting at the first failing stage.
|
|
31
|
+
const { diagnostics } = lintMthds(mthdsSource);
|
|
32
|
+
// diagnostics: [{ kind, severity, message, location, range }, ...] — empty == clean
|
|
33
|
+
|
|
34
|
+
// Format with the canonical MTHDS defaults; never throws on malformed MTHDS
|
|
35
|
+
// (the input comes back unchanged with the blocking diagnostics).
|
|
36
|
+
const { formatted, changed, diagnostics: formatDiagnostics } = formatMthds(mthdsSource);
|
|
37
|
+
|
|
38
|
+
// Formatter overrides use the same snake_case keys as `plxt fmt -o key=value`
|
|
39
|
+
// and the API's /v1/format options passthrough.
|
|
40
|
+
formatMthds(mthdsSource, { column_width: 100, align_entries: false });
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
The `Diagnostic` shape mirrors `@pipelex/sdk`'s `Diagnostic`/`DiagnosticRange`/`DiagnosticKind`: `location` and `range` are `null` (never absent) when the analysis cannot attribute a span.
|
|
44
|
+
|
|
45
|
+
## Development
|
|
46
|
+
|
|
47
|
+
Built from [`crates/pipelex-tools-wasm`](https://github.com/Pipelex/vscode-pipelex/tree/main/crates/pipelex-tools-wasm) via rollup + `@wasm-tool/rollup-plugin-rust`, with the WASM inlined into a single UMD bundle.
|
|
48
|
+
|
|
49
|
+
```sh
|
|
50
|
+
yarn build # debug build (RELEASE=true yarn build for the release artifact)
|
|
51
|
+
yarn test # vitest over the built bundle + the repo's MTHDS fixture corpus
|
|
52
|
+
```
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/** Which analysis produced a `Diagnostic` — mirror of `pipelex-tools`' closed kind set. */
|
|
2
|
+
export type DiagnosticKind = "syntax" | "semantic" | "schema";
|
|
3
|
+
/** Source span of a `Diagnostic` — byte offsets plus 1-based line/column coordinates. */
|
|
4
|
+
export interface DiagnosticRange {
|
|
5
|
+
start_offset: number;
|
|
6
|
+
end_offset: number;
|
|
7
|
+
start_line: number;
|
|
8
|
+
start_col: number;
|
|
9
|
+
end_line: number;
|
|
10
|
+
end_col: number;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* One structured lint/format diagnostic — mirror of pipelex's `Diagnostic`.
|
|
14
|
+
* `severity` stays an open string (the engine does not close the vocabulary);
|
|
15
|
+
* `location` and `range` are `null` when the analysis cannot attribute a span.
|
|
16
|
+
*/
|
|
17
|
+
export interface Diagnostic {
|
|
18
|
+
kind: DiagnosticKind;
|
|
19
|
+
severity: string;
|
|
20
|
+
message: string;
|
|
21
|
+
location: string | null;
|
|
22
|
+
range: DiagnosticRange | null;
|
|
23
|
+
}
|
|
24
|
+
/** Result of {@link lintMthds} — the diagnostics of one linted `.mthds` file (empty == clean). */
|
|
25
|
+
export interface LintResult {
|
|
26
|
+
diagnostics: Diagnostic[];
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Result of {@link formatMthds} — the canonically formatted content, whether it
|
|
30
|
+
* differs from the submitted one, and any diagnostics found on the way. A syntax
|
|
31
|
+
* error yields `changed: false` with the content echoed back unchanged.
|
|
32
|
+
*/
|
|
33
|
+
export interface FormatResult {
|
|
34
|
+
formatted: string;
|
|
35
|
+
changed: boolean;
|
|
36
|
+
diagnostics: Diagnostic[];
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Formatter overrides for {@link formatMthds}: snake_case option keys with
|
|
40
|
+
* string, number, or boolean values — the same keys as the CLI's `-o key=value`
|
|
41
|
+
* and the API's `/v1/format` `options` passthrough (e.g. `column_width`,
|
|
42
|
+
* `align_entries`, `indent_string`).
|
|
43
|
+
*/
|
|
44
|
+
export type FormatMthdsOptions = Record<string, string | number | boolean>;
|
|
45
|
+
/**
|
|
46
|
+
* Load the WASM module (once) and install its panic hook. Must complete before
|
|
47
|
+
* the first {@link lintMthds} / {@link formatMthds} call; calling it again is a
|
|
48
|
+
* cheap no-op.
|
|
49
|
+
*/
|
|
50
|
+
export declare function initialize(): Promise<void>;
|
|
51
|
+
/**
|
|
52
|
+
* Lint one MTHDS document: syntax → semantic → schema, short-circuiting at the
|
|
53
|
+
* first failing stage, fully offline against the embedded MTHDS schema.
|
|
54
|
+
* Diagnostics are data — this never throws on bad content.
|
|
55
|
+
*/
|
|
56
|
+
export declare function lintMthds(content: string): LintResult;
|
|
57
|
+
/**
|
|
58
|
+
* Format one MTHDS document with the canonical MTHDS defaults baked in. On a
|
|
59
|
+
* syntax error the input is returned unchanged along with the blocking
|
|
60
|
+
* diagnostics — it never throws for malformed MTHDS. It *does* throw for a
|
|
61
|
+
* malformed `options` value (e.g. a non-numeric `column_width`).
|
|
62
|
+
*/
|
|
63
|
+
export declare function formatMthds(content: string, options?: FormatMthdsOptions): FormatResult;
|