teptris 0.3.21 → 0.3.23
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 +1 -0
- package/dist/teptris.wasm +0 -0
- package/package.json +1 -1
- package/src/index.d.ts +29 -0
- package/src/index.js +23 -8
package/README.md
CHANGED
|
@@ -16,6 +16,7 @@ const teptris = await init();
|
|
|
16
16
|
teptris.loads('a = 1'); // → { a: 1 }
|
|
17
17
|
teptris.dump(obj); // → canonical TOML string
|
|
18
18
|
teptris.dumpJson(obj); // → natural JSON string
|
|
19
|
+
teptris.edit(src, "serve.port", "9090"); // → the file with ONE value rewritten
|
|
19
20
|
teptris.engineVersion(); // → the libteptris inside
|
|
20
21
|
```
|
|
21
22
|
|
package/dist/teptris.wasm
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "teptris",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.23",
|
|
4
4
|
"description": "TOML for JavaScript/TypeScript at libteptris speed (WebAssembly, no fallback) - version tracks the engine ({engine}.{iteration}; npm semver is 3-part)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.js",
|
package/src/index.d.ts
CHANGED
|
@@ -61,6 +61,28 @@ export interface TeptrisApi {
|
|
|
61
61
|
/** The libteptris engine version inside this build. */
|
|
62
62
|
engineVersion(): string;
|
|
63
63
|
|
|
64
|
+
/** Parse TOML into a retained engine document (no host objects):
|
|
65
|
+
* the LOSSLESS round-trip surface. JS numbers cannot carry TOML's
|
|
66
|
+
* int/float distinction (loads' documented floor) - doc handles
|
|
67
|
+
* can: dumpDoc(loadsDoc(s)) re-emits the parsed tree exactly, at
|
|
68
|
+
* C speed with nothing materialized in JS. Single slot: a later
|
|
69
|
+
* loadsDoc replaces the held document. */
|
|
70
|
+
loadsDoc(toml: string): TeptrisDoc;
|
|
71
|
+
|
|
72
|
+
/** Emit a loadsDoc() document back to canonical TOML — the
|
|
73
|
+
* lossless half of the doc round-trip. */
|
|
74
|
+
dumpDoc(doc: TeptrisDoc): string;
|
|
75
|
+
|
|
76
|
+
/** Format-preserving edit: rewrite exactly the value bytes of one
|
|
77
|
+
* key = value line; every other byte of the source survives
|
|
78
|
+
* (comments, blank lines, formatting, CRLF endings). keyPath may
|
|
79
|
+
* carry a [table] prefix ("t.x" edits x inside [t]); a dotted key
|
|
80
|
+
* line may continue the open section. replacement is the value's
|
|
81
|
+
* TEXT, validated by the engine; multiline strings and inline
|
|
82
|
+
* collections splice (parse-verified). Throws Error on an absent
|
|
83
|
+
* key or a malformed span/replacement. */
|
|
84
|
+
edit(source: string, keyPath: string, replacement: string): string;
|
|
85
|
+
|
|
64
86
|
/** Compile a descriptor plan (once) — materialize only the planned
|
|
65
87
|
* keys of any document via planWalk. Rows: a string name is a
|
|
66
88
|
* scalar; kind "collection" walks an array; kind "raw" takes the
|
|
@@ -76,6 +98,13 @@ export interface TeptrisApi {
|
|
|
76
98
|
planFree(plan: number): void;
|
|
77
99
|
}
|
|
78
100
|
|
|
101
|
+
/** An opaque retained-document handle from {@link TeptrisApi.loadsDoc}
|
|
102
|
+
* (single slot: a later loadsDoc replaces the held document). */
|
|
103
|
+
export interface TeptrisDoc {
|
|
104
|
+
/** Renders "[teptris doc]". */
|
|
105
|
+
toString(): string;
|
|
106
|
+
}
|
|
107
|
+
|
|
79
108
|
/** One planned key of a {@link PlanRowSpec} tree. */
|
|
80
109
|
export interface PlanRowSpec {
|
|
81
110
|
name: string;
|
package/src/index.js
CHANGED
|
@@ -10,6 +10,21 @@ function cstr(mod, s) {
|
|
|
10
10
|
return ptr;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
+
// The len-bounded fast path: TextEncoder.encodeInto writes UTF-8
|
|
14
|
+
// STRAIGHT into the wasm heap with the native encoder, replacing
|
|
15
|
+
// emscripten's two JS-loop passes (lengthBytesUTF8 + stringToUTF8) -
|
|
16
|
+
// the measured biggest JS-side cost of the loads crossing. Only for
|
|
17
|
+
// entry points whose C side takes an explicit length (no NUL needed);
|
|
18
|
+
// NUL-terminated destinations keep cstr.
|
|
19
|
+
const utf8Encoder = new TextEncoder();
|
|
20
|
+
|
|
21
|
+
function cstrLen(mod, s) {
|
|
22
|
+
const cap = s.length * 3 + 4; /* UTF-8 worst case: 3 bytes/unit */
|
|
23
|
+
const ptr = mod._teptris_wasm_alloc(cap);
|
|
24
|
+
const { written } = utf8Encoder.encodeInto(s, mod.HEAPU8.subarray(ptr, ptr + cap));
|
|
25
|
+
return { ptr, len: written };
|
|
26
|
+
}
|
|
27
|
+
|
|
13
28
|
function freeCstr(mod, ptr) { mod._teptris_wasm_free(ptr); }
|
|
14
29
|
|
|
15
30
|
// RFC 3339-ish (the four TOML shapes) back into builder fields
|
|
@@ -148,8 +163,8 @@ export function initApi(mod) {
|
|
|
148
163
|
if (typeof toml !== "string") {
|
|
149
164
|
throw new TypeError("loads expects a string");
|
|
150
165
|
}
|
|
151
|
-
const ptr =
|
|
152
|
-
const st = mod._teptris_wasm_load(ptr,
|
|
166
|
+
const { ptr, len } = cstrLen(mod, toml);
|
|
167
|
+
const st = mod._teptris_wasm_load(ptr, len);
|
|
153
168
|
let value = null, error = null;
|
|
154
169
|
if (st === 0) {
|
|
155
170
|
const jptr = mod._teptris_wasm_json();
|
|
@@ -428,8 +443,8 @@ export function initApi(mod) {
|
|
|
428
443
|
if (typeof toml !== "string") {
|
|
429
444
|
throw new TypeError("loadsDoc expects a string");
|
|
430
445
|
}
|
|
431
|
-
const ptr =
|
|
432
|
-
const st = mod._teptris_wasm_load_doc(ptr,
|
|
446
|
+
const { ptr, len } = cstrLen(mod, toml);
|
|
447
|
+
const st = mod._teptris_wasm_load_doc(ptr, len);
|
|
433
448
|
freeCstr(mod, ptr);
|
|
434
449
|
if (st !== 0) {
|
|
435
450
|
docHeld = false;
|
|
@@ -567,8 +582,8 @@ export function initApi(mod) {
|
|
|
567
582
|
if (typeof toml !== "string") {
|
|
568
583
|
throw new TypeError("planWalk expects a TOML string");
|
|
569
584
|
}
|
|
570
|
-
const p =
|
|
571
|
-
const st = mod._teptris_wasm_plan_walk(plan, p,
|
|
585
|
+
const { ptr: p, len: plen } = cstrLen(mod, toml);
|
|
586
|
+
const st = mod._teptris_wasm_plan_walk(plan, p, plen);
|
|
572
587
|
freeCstr(mod, p);
|
|
573
588
|
if (st !== 0) {
|
|
574
589
|
throw planError();
|
|
@@ -594,11 +609,11 @@ export function initApi(mod) {
|
|
|
594
609
|
throw new TypeError("edit expects three strings");
|
|
595
610
|
}
|
|
596
611
|
}
|
|
597
|
-
const sp =
|
|
612
|
+
const { ptr: sp, len: slen } = cstrLen(mod, source);
|
|
598
613
|
const kp = cstr(mod, keyPath);
|
|
599
614
|
const rp = cstr(mod, replacement);
|
|
600
615
|
let out = null, error = null;
|
|
601
|
-
const st = mod._teptris_wasm_edit(sp,
|
|
616
|
+
const st = mod._teptris_wasm_edit(sp, slen, kp, rp);
|
|
602
617
|
if (st === 0) {
|
|
603
618
|
const optr = mod._teptris_wasm_json();
|
|
604
619
|
const olen = mod._teptris_wasm_json_len();
|