1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
// SPDX-License-Identifier: MIT OR Apache-2.0
// Copyright (c) 2026 Noyalib. All rights reserved.
//! noyalib WASM bindings.
//!
//! Exposes YAML parse/serialize and the lossless Document API to JavaScript
//! via wasm-bindgen.
//!
//! The pure-Rust logic lives in [`core`] so it is reachable from
//! `cargo test` on the rlib side; the bindings in this module are
//! the thin JsValue conversion shells.
//!
//! # Cargo features
//!
//! - **`wasm-opt`** *(optional, off by default)* — enables a
//! post-build pass that re-runs Binaryen's `wasm-opt -O3 -s`
//! on the produced `.wasm` to shrink the bundle (~17% smaller
//! on `noyalib-wasm`). Pulls in no extra Rust dependencies; it
//! is a build-script feature only. Disable for fastest dev
//! builds.
//!
//! Optional `noyalib` features pulled in by a downstream wasm-pack
//! consumer (`schema`, `parallel` …) compile against the
//! `wasm32-unknown-unknown` target only when their dep tree is
//! WASM-clean — `parallel` (rayon) requires
//! `--target wasm32-wasip1-threads`, not the default browser
//! target. The canonical `noyalib` feature matrix lives in
//! [`crates/noyalib/src/lib.rs`](https://docs.rs/noyalib).
//!
//! # MSRV
//!
//! **Rust 1.85.0** stable. The `wasm-bindgen` 0.2 ecosystem
//! pulls helpers floored at 1.85; the core `noyalib` library
//! still builds on **1.75**. See workspace
//! [`POLICIES.md`](https://github.com/sebastienrousseau/noyalib/blob/main/doc/POLICIES.md#1-msrv-minimum-supported-rust-version).
//!
//! # Panics
//!
//! Public bindings do not panic on well-formed input. Rust-side
//! parse / serialise errors are converted to `JsError` values
//! that JavaScript receives as a thrown `Error`; the bindings
//! never `unwrap` user-supplied data. The remaining sources of
//! panic on the WebAssembly instance are environmental, not
//! logic, and are documented here for completeness:
//!
//! - **WASM linear-memory exhaustion (OOM).** Allocating a Vec
//! or String larger than the host's WASM memory limit aborts
//! the instance. Browsers default to a 4 GiB cap on
//! `wasm32-unknown-unknown`. Bound `noyalib` resource use
//! ahead of time via `ParserConfig::strict()` or explicit
//! `max_*` budgets to fail with a structured `Error::Budget`
//! instead of an OOM abort.
//! - **Stack overflow.** Pathologically deep YAML (>4096 nested
//! nodes by default) is rejected with `Error::RecursionLimitExceeded`
//! long before the WASM stack overflows; deliberately
//! misconfigured `max_depth` may overflow the host stack.
//! - **Host abort on `panic = abort`.** Every release build
//! uses `panic = abort` (per `Cargo.toml`), so any logic-level
//! panic terminates the WebAssembly instance with no chance
//! of `catch_unwind`. `console_error_panic_hook` is wired in
//! `examples/` so debug builds surface a JS-readable trace
//! before the abort.
//!
//! # Errors
//!
//! Every fallible binding returns `Result<JsValue, JsError>`;
//! the `JsError` carries the Rust-side `Display` text from
//! [`noyalib::Error`]. JavaScript callers handle these as
//! standard thrown errors — `try { … } catch (e) { e.message }`.
//!
//! # Concurrency
//!
//! WebAssembly is single-threaded on browsers (without
//! shared-memory + `--enable-experimental-features`). The
//! bindings hold no internal state outside the `WasmDocument`
//! handle; multi-document workloads simply construct multiple
//! handles. Web Workers hosting independent WASM instances are
//! the recommended way to parallelise on the browser.
//!
//! # Platform support
//!
//! Builds against every wasm-pack target: `bundler` (Webpack /
//! Rollup / esbuild / Vite), `web` (native ES module), `nodejs`
//! (CommonJS), `deno`, `no-modules` (plain global). CI verifies
//! the `wasm32-unknown-unknown` target each PR via
//! `wasm-pack test --node`. Cloudflare Workers, Deno, and Bun
//! consume the `bundler` target via their own packaging step;
//! see [`crates/noyalib-wasm/doc/bundling.md`](https://github.com/sebastienrousseau/noyalib/blob/main/crates/noyalib-wasm/doc/bundling.md).
//!
//! # Performance
//!
//! Release bundle size: ~338 KB raw, ~140 KB gzip. With the
//! optional `wasm-opt` post-build pass (`--features wasm-opt`):
//! ~280 KB raw, ~115 KB gzip. Tree-shaking-friendly: the
//! `WasmDocument` API and the plain `parse` / `stringify` API
//! are independent modules; bundlers drop whichever your code
//! does not import.
//!
//! # Security
//!
//! `#![forbid(unsafe_code)]`. No `unsafe` outside `wasm-bindgen`'s
//! own bridge. No network I/O. No filesystem access (browsers
//! sandbox WASM by default; Node and Deno hosts can grant fs
//! access to the host process, but this crate's bindings do
//! not expose it). Resource-limit gates are inherited from
//! `noyalib`'s `ParserConfig` defaults. Full posture:
//! [`SECURITY.md`](https://github.com/sebastienrousseau/noyalib/blob/main/SECURITY.md).
//!
//! # API stability and SemVer
//!
//! Pre-1.0 (`0.0.x`): the JavaScript-facing API (`parse`,
//! `stringify`, `WasmDocument` shape, JSON shape of returned
//! values) is **stable** within a 0.0.x line — bug fixes only.
//! Adding a new method or option is allowed within a 0.0.x
//! bump; removing or renaming an exported binding, or changing
//! the JSON shape of a returned object, is held to a 0.x bump
//! (e.g. 0.0.x → 0.1.0). The Rust library surface (`WasmDocument`,
//! `core::*`) is covered by the workspace SemVer policy in
//! [`POLICIES.md`](https://github.com/sebastienrousseau/noyalib/blob/main/doc/POLICIES.md#2-semver--api-stability).
//! `cargo-semver-checks` runs in CI on every PR.
//!
//! # Documentation
//!
//! - **Engineering policies** — workspace
//! [`POLICIES.md`](https://github.com/sebastienrousseau/noyalib/blob/main/doc/POLICIES.md).
//! - **JS API reference**:
//! [`doc/js-api.md`](https://github.com/sebastienrousseau/noyalib/blob/main/crates/noyalib-wasm/doc/js-api.md).
//! - **Bundling guide** (Vite, Webpack, Next.js, Cloudflare,
//! Deno, Bun):
//! [`doc/bundling.md`](https://github.com/sebastienrousseau/noyalib/blob/main/crates/noyalib-wasm/doc/bundling.md).
//! - **Browser / Node demos**:
//! [`examples/`](https://github.com/sebastienrousseau/noyalib/tree/main/crates/noyalib-wasm/examples).
use ;
use Serialize;
use *;
/// Convert a Rust value to a `JsValue` using the JS-friendly
/// serializer config:
///
/// - **Mappings** become plain JS Objects (`{ name: 'foo' }`),
/// not the `Map` instance `serde_wasm_bindgen`'s default
/// produces. End users overwhelmingly expect dot-property
/// access (`value.name`) rather than `.get('name')`.
/// - Other defaults are preserved.
Sized>
/// A YAML document with byte-faithful source preservation and path-targeted edits.
// ── Legacy / Simple API ──────────────────────────────────────────────────────
/// Parse a YAML string and return a JS object.
/// Serialize a JS object to a YAML string.
/// Validate YAML against the JSON-compatible schema. Bound on the
/// JS side as `validateJson(yaml)` per JS naming conventions.
/// Get a value at a dotted path from a YAML string. Bound on the
/// JS side as `getPath(yaml, path)` per JS naming conventions.
/// Merge two YAML documents.