@quillmark/wasm 0.81.0-rc.1 → 0.81.0-rc.2
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 +62 -4
- package/bundler/wasm.d.ts +45 -1
- package/bundler/wasm_bg.js +87 -1
- package/bundler/wasm_bg.wasm +0 -0
- package/bundler/wasm_bg.wasm.d.ts +3 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -69,7 +69,7 @@ semantic equality.
|
|
|
69
69
|
|
|
70
70
|
### `doc.toJson()`
|
|
71
71
|
Serialize the document to a versioned storage DTO — a JSON **string**
|
|
72
|
-
carrying a `schema` version
|
|
72
|
+
carrying a `schema` version. Use this (not `toMarkdown`) to persist a
|
|
73
73
|
document across a process restart or crate upgrade: the wire format is
|
|
74
74
|
frozen per `schema` version, whereas Markdown syntax evolves. Parse-time
|
|
75
75
|
`warnings` are not part of the DTO.
|
|
@@ -79,6 +79,13 @@ global is not involved. It is standard JSON text, so callers may
|
|
|
79
79
|
`JSON.parse` it to inspect it — but it is intended as an opaque blob you
|
|
80
80
|
persist and hand back.
|
|
81
81
|
|
|
82
|
+
`toJson()` is **deterministic**: a `Document` that is `equals` to another
|
|
83
|
+
serializes to a byte-identical string — across repeated calls, and across
|
|
84
|
+
any crate upgrade that keeps the same `schema` version (every release does until
|
|
85
|
+
the `Document` model changes; see [Storage compatibility](#storage-compatibility-across-versions)).
|
|
86
|
+
Field order is fixed and object key order is preserved, so content hashes
|
|
87
|
+
and string-equality dirty-checks over the output are stable.
|
|
88
|
+
|
|
82
89
|
### `Document.fromJson(json)`
|
|
83
90
|
Reconstruct a `Document` from a storage DTO string produced by `toJson`.
|
|
84
91
|
Round-trips losslessly:
|
|
@@ -89,9 +96,57 @@ const restored = Document.fromJson(stored);
|
|
|
89
96
|
restored.equals(doc); // true
|
|
90
97
|
```
|
|
91
98
|
|
|
92
|
-
Throws a JS `Error` on malformed JSON, an unknown `schema`
|
|
99
|
+
Throws a JS `Error` on malformed JSON, an unknown `schema` version, or a
|
|
93
100
|
malformed payload. The restored document has no parse-time `warnings`.
|
|
94
101
|
|
|
102
|
+
### `Document.tryFromJson(json)`
|
|
103
|
+
Like `fromJson`, but returns `undefined` instead of throwing when `json` is
|
|
104
|
+
not a valid storage DTO. Use it to branch on format without a heuristic or
|
|
105
|
+
`try`/`catch` as control flow:
|
|
106
|
+
|
|
107
|
+
```ts
|
|
108
|
+
// "JSON canonical, Markdown fallback" — no exceptions, no string sniffing
|
|
109
|
+
const doc = Document.tryFromJson(content) ?? Document.fromMarkdown(content);
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
`undefined` means only "not a storage DTO"; `fromMarkdown` still throws on
|
|
113
|
+
genuinely malformed Markdown.
|
|
114
|
+
|
|
115
|
+
### Storage compatibility across versions
|
|
116
|
+
|
|
117
|
+
The `schema` value (`quillmark/document@0.81.0`) is the **model version**,
|
|
118
|
+
not the running crate version. It is a hand-set constant, bumped only when
|
|
119
|
+
the `Document` model itself changes — so every `0.81.x` patch release reads
|
|
120
|
+
and writes that same value.
|
|
121
|
+
|
|
122
|
+
- **Upgrading is safe.** A newer build always reads documents written by an
|
|
123
|
+
older one. Each schema version's wire format is frozen and never changes;
|
|
124
|
+
when the model does change, the new build ships a migration that converts
|
|
125
|
+
old payloads on `fromJson`. A document you commit as your canonical
|
|
126
|
+
on-disk format keeps loading across crate upgrades — there is no need to
|
|
127
|
+
pin old wasm to read old data.
|
|
128
|
+
- **Downgrading is not.** `fromJson` rejects an *unknown* (i.e. newer)
|
|
129
|
+
`schema` version rather than guessing at a format it predates. Don't feed
|
|
130
|
+
documents written by a newer build back into an older one.
|
|
131
|
+
|
|
132
|
+
To detect a version mismatch before parsing, use the static accessors:
|
|
133
|
+
|
|
134
|
+
```ts
|
|
135
|
+
const v = Document.schemaVersionOf(blob); // undefined | string
|
|
136
|
+
if (v && v !== Document.currentSchemaVersion()) {
|
|
137
|
+
// payload is from a build with a different model version
|
|
138
|
+
}
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
`schemaVersionOf` does not validate the payload — it only reads the
|
|
142
|
+
`schema` field, returning `undefined` for non-JSON, non-objects, or
|
|
143
|
+
payloads that don't carry one. Use it to distinguish "wrong version" from
|
|
144
|
+
"corrupt" when `fromJson` throws.
|
|
145
|
+
|
|
146
|
+
In short: persist the `toJson` string, upgrade freely, never downgrade. The
|
|
147
|
+
full design — including how migrations are added — is in
|
|
148
|
+
`prose/canon/DOCUMENT_STORAGE.md`.
|
|
149
|
+
|
|
95
150
|
### `doc.equals(other)`
|
|
96
151
|
Structural equality between two `Document` handles. Compares `main` and
|
|
97
152
|
`cards` by value; parse-time `warnings` are intentionally excluded.
|
|
@@ -218,8 +273,11 @@ compilation failures. The same shape applies to every throw site:
|
|
|
218
273
|
The wasm bindings are built with `--weak-refs`, so dropped `Document`,
|
|
219
274
|
`Quill`, and `RenderSession` handles are reclaimed by `FinalizationRegistry`
|
|
220
275
|
without manual `.free()` discipline. `.free()` is still emitted as an eager
|
|
221
|
-
teardown hook for callers that want deterministic release.
|
|
222
|
-
|
|
276
|
+
teardown hook for callers that want deterministic release.
|
|
277
|
+
|
|
278
|
+
The package requires Node 24+ (`engines: { node: ">=24" }`) and current
|
|
279
|
+
evergreen browsers; `--weak-refs` itself only needs Node 14.6+, but the
|
|
280
|
+
published package floor is 24.
|
|
223
281
|
|
|
224
282
|
For environments where `using` (the [explicit resource management][erm]
|
|
225
283
|
proposal) hasn't landed, use an explicit `try` / `finally`:
|
package/bundler/wasm.d.ts
CHANGED
|
@@ -269,6 +269,14 @@ export class Document {
|
|
|
269
269
|
* history of either handle.
|
|
270
270
|
*/
|
|
271
271
|
clone(): Document;
|
|
272
|
+
/**
|
|
273
|
+
* Schema version this build writes via [`toJson`](Document::to_json).
|
|
274
|
+
*
|
|
275
|
+
* Compare a payload's [`schemaVersionOf`](Document::schema_version_of)
|
|
276
|
+
* against this to detect mismatches before calling
|
|
277
|
+
* [`fromJson`](Document::from_json).
|
|
278
|
+
*/
|
|
279
|
+
static currentSchemaVersion(): string;
|
|
272
280
|
/**
|
|
273
281
|
* Structural equality against another `Document`.
|
|
274
282
|
*
|
|
@@ -364,6 +372,27 @@ export class Document {
|
|
|
364
372
|
* Mutators never modify `warnings`.
|
|
365
373
|
*/
|
|
366
374
|
replaceBody(body: string): void;
|
|
375
|
+
/**
|
|
376
|
+
* Read the schema version from a raw storage DTO string without
|
|
377
|
+
* performing a full parse, or `undefined`.
|
|
378
|
+
*
|
|
379
|
+
* Returns the `schema` field as-is — including unknown future versions
|
|
380
|
+
* that `fromJson` would reject. Use this to distinguish "this build is
|
|
381
|
+
* too old for the payload" from "the payload is corrupt" when
|
|
382
|
+
* [`fromJson`](Document::from_json) throws:
|
|
383
|
+
*
|
|
384
|
+
* ```js
|
|
385
|
+
* const v = Document.schemaVersionOf(blob);
|
|
386
|
+
* if (v === undefined) {
|
|
387
|
+
* // not a stored DTO at all — try fromMarkdown
|
|
388
|
+
* } else if (v !== Document.currentSchemaVersion()) {
|
|
389
|
+
* // newer (or older unmigrated) schema — prompt the user to upgrade
|
|
390
|
+
* } else {
|
|
391
|
+
* doc = Document.fromJson(blob);
|
|
392
|
+
* }
|
|
393
|
+
* ```
|
|
394
|
+
*/
|
|
395
|
+
static schemaVersionOf(json: string): string | undefined;
|
|
367
396
|
/**
|
|
368
397
|
* Replace the tag of the composable card at `index`.
|
|
369
398
|
*
|
|
@@ -413,7 +442,7 @@ export class Document {
|
|
|
413
442
|
* Serialize this document to a versioned storage DTO string.
|
|
414
443
|
*
|
|
415
444
|
* Returns the document as a JSON string carrying a `schema` version
|
|
416
|
-
*
|
|
445
|
+
* field. The string is produced inside the module via `serde_json` and
|
|
417
446
|
* round-trips losslessly back to an equal `Document` via
|
|
418
447
|
* [`fromJson`](Document::from_json) — the JS `JSON` global is not
|
|
419
448
|
* involved in either direction.
|
|
@@ -436,6 +465,21 @@ export class Document {
|
|
|
436
465
|
* produces a `Document` equal to `self` by value and by type.
|
|
437
466
|
*/
|
|
438
467
|
toMarkdown(): string;
|
|
468
|
+
/**
|
|
469
|
+
* Reconstruct a `Document` from a storage DTO string, or `undefined`.
|
|
470
|
+
*
|
|
471
|
+
* Like [`fromJson`](Document::from_json), but returns `undefined`
|
|
472
|
+
* instead of throwing when `json` is not a valid storage DTO. Use this
|
|
473
|
+
* to detect format and fall back without exceptions as control flow:
|
|
474
|
+
*
|
|
475
|
+
* ```js
|
|
476
|
+
* const doc = Document.tryFromJson(content) ?? Document.fromMarkdown(content);
|
|
477
|
+
* ```
|
|
478
|
+
*
|
|
479
|
+
* `undefined` only ever means "not a storage DTO" — `fromMarkdown`
|
|
480
|
+
* still throws on genuinely malformed markdown.
|
|
481
|
+
*/
|
|
482
|
+
static tryFromJson(json: string): Document | undefined;
|
|
439
483
|
/**
|
|
440
484
|
* Replace the body of the card at `index`.
|
|
441
485
|
*
|
package/bundler/wasm_bg.js
CHANGED
|
@@ -61,6 +61,30 @@ export class Document {
|
|
|
61
61
|
const ret = wasm.document_clone(this.__wbg_ptr);
|
|
62
62
|
return Document.__wrap(ret);
|
|
63
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* Schema version this build writes via [`toJson`](Document::to_json).
|
|
66
|
+
*
|
|
67
|
+
* Compare a payload's [`schemaVersionOf`](Document::schema_version_of)
|
|
68
|
+
* against this to detect mismatches before calling
|
|
69
|
+
* [`fromJson`](Document::from_json).
|
|
70
|
+
* @returns {string}
|
|
71
|
+
*/
|
|
72
|
+
static currentSchemaVersion() {
|
|
73
|
+
let deferred1_0;
|
|
74
|
+
let deferred1_1;
|
|
75
|
+
try {
|
|
76
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
77
|
+
wasm.document_currentSchemaVersion(retptr);
|
|
78
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
79
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
80
|
+
deferred1_0 = r0;
|
|
81
|
+
deferred1_1 = r1;
|
|
82
|
+
return getStringFromWasm0(r0, r1);
|
|
83
|
+
} finally {
|
|
84
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
85
|
+
wasm.__wbindgen_export4(deferred1_0, deferred1_1, 1);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
64
88
|
/**
|
|
65
89
|
* Structural equality against another `Document`.
|
|
66
90
|
*
|
|
@@ -320,6 +344,46 @@ export class Document {
|
|
|
320
344
|
const len0 = WASM_VECTOR_LEN;
|
|
321
345
|
wasm.document_replaceBody(this.__wbg_ptr, ptr0, len0);
|
|
322
346
|
}
|
|
347
|
+
/**
|
|
348
|
+
* Read the schema version from a raw storage DTO string without
|
|
349
|
+
* performing a full parse, or `undefined`.
|
|
350
|
+
*
|
|
351
|
+
* Returns the `schema` field as-is — including unknown future versions
|
|
352
|
+
* that `fromJson` would reject. Use this to distinguish "this build is
|
|
353
|
+
* too old for the payload" from "the payload is corrupt" when
|
|
354
|
+
* [`fromJson`](Document::from_json) throws:
|
|
355
|
+
*
|
|
356
|
+
* ```js
|
|
357
|
+
* const v = Document.schemaVersionOf(blob);
|
|
358
|
+
* if (v === undefined) {
|
|
359
|
+
* // not a stored DTO at all — try fromMarkdown
|
|
360
|
+
* } else if (v !== Document.currentSchemaVersion()) {
|
|
361
|
+
* // newer (or older unmigrated) schema — prompt the user to upgrade
|
|
362
|
+
* } else {
|
|
363
|
+
* doc = Document.fromJson(blob);
|
|
364
|
+
* }
|
|
365
|
+
* ```
|
|
366
|
+
* @param {string} json
|
|
367
|
+
* @returns {string | undefined}
|
|
368
|
+
*/
|
|
369
|
+
static schemaVersionOf(json) {
|
|
370
|
+
try {
|
|
371
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
372
|
+
const ptr0 = passStringToWasm0(json, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
373
|
+
const len0 = WASM_VECTOR_LEN;
|
|
374
|
+
wasm.document_schemaVersionOf(retptr, ptr0, len0);
|
|
375
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
376
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
377
|
+
let v2;
|
|
378
|
+
if (r0 !== 0) {
|
|
379
|
+
v2 = getStringFromWasm0(r0, r1).slice();
|
|
380
|
+
wasm.__wbindgen_export4(r0, r1 * 1, 1);
|
|
381
|
+
}
|
|
382
|
+
return v2;
|
|
383
|
+
} finally {
|
|
384
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
385
|
+
}
|
|
386
|
+
}
|
|
323
387
|
/**
|
|
324
388
|
* Replace the tag of the composable card at `index`.
|
|
325
389
|
*
|
|
@@ -432,7 +496,7 @@ export class Document {
|
|
|
432
496
|
* Serialize this document to a versioned storage DTO string.
|
|
433
497
|
*
|
|
434
498
|
* Returns the document as a JSON string carrying a `schema` version
|
|
435
|
-
*
|
|
499
|
+
* field. The string is produced inside the module via `serde_json` and
|
|
436
500
|
* round-trips losslessly back to an equal `Document` via
|
|
437
501
|
* [`fromJson`](Document::from_json) — the JS `JSON` global is not
|
|
438
502
|
* involved in either direction.
|
|
@@ -495,6 +559,28 @@ export class Document {
|
|
|
495
559
|
wasm.__wbindgen_export4(deferred1_0, deferred1_1, 1);
|
|
496
560
|
}
|
|
497
561
|
}
|
|
562
|
+
/**
|
|
563
|
+
* Reconstruct a `Document` from a storage DTO string, or `undefined`.
|
|
564
|
+
*
|
|
565
|
+
* Like [`fromJson`](Document::from_json), but returns `undefined`
|
|
566
|
+
* instead of throwing when `json` is not a valid storage DTO. Use this
|
|
567
|
+
* to detect format and fall back without exceptions as control flow:
|
|
568
|
+
*
|
|
569
|
+
* ```js
|
|
570
|
+
* const doc = Document.tryFromJson(content) ?? Document.fromMarkdown(content);
|
|
571
|
+
* ```
|
|
572
|
+
*
|
|
573
|
+
* `undefined` only ever means "not a storage DTO" — `fromMarkdown`
|
|
574
|
+
* still throws on genuinely malformed markdown.
|
|
575
|
+
* @param {string} json
|
|
576
|
+
* @returns {Document | undefined}
|
|
577
|
+
*/
|
|
578
|
+
static tryFromJson(json) {
|
|
579
|
+
const ptr0 = passStringToWasm0(json, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
580
|
+
const len0 = WASM_VECTOR_LEN;
|
|
581
|
+
const ret = wasm.document_tryFromJson(ptr0, len0);
|
|
582
|
+
return ret === 0 ? undefined : Document.__wrap(ret);
|
|
583
|
+
}
|
|
498
584
|
/**
|
|
499
585
|
* Replace the body of the card at `index`.
|
|
500
586
|
*
|
package/bundler/wasm_bg.wasm
CHANGED
|
Binary file
|
|
@@ -8,6 +8,7 @@ export const __wbg_rendersession_free: (a: number, b: number) => void;
|
|
|
8
8
|
export const document_cardCount: (a: number) => number;
|
|
9
9
|
export const document_cards: (a: number) => number;
|
|
10
10
|
export const document_clone: (a: number) => number;
|
|
11
|
+
export const document_currentSchemaVersion: (a: number) => void;
|
|
11
12
|
export const document_equals: (a: number, b: number) => number;
|
|
12
13
|
export const document_fromJson: (a: number, b: number, c: number) => void;
|
|
13
14
|
export const document_fromMarkdown: (a: number, b: number, c: number) => void;
|
|
@@ -20,12 +21,14 @@ export const document_removeCard: (a: number, b: number) => number;
|
|
|
20
21
|
export const document_removeCardField: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
21
22
|
export const document_removeField: (a: number, b: number, c: number, d: number) => void;
|
|
22
23
|
export const document_replaceBody: (a: number, b: number, c: number) => void;
|
|
24
|
+
export const document_schemaVersionOf: (a: number, b: number, c: number) => void;
|
|
23
25
|
export const document_setCardTag: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
24
26
|
export const document_setField: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
25
27
|
export const document_setFill: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
26
28
|
export const document_setQuillRef: (a: number, b: number, c: number, d: number) => void;
|
|
27
29
|
export const document_toJson: (a: number, b: number) => void;
|
|
28
30
|
export const document_toMarkdown: (a: number, b: number) => void;
|
|
31
|
+
export const document_tryFromJson: (a: number, b: number) => number;
|
|
29
32
|
export const document_updateCardBody: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
30
33
|
export const document_updateCardField: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
|
31
34
|
export const document_warnings: (a: number) => number;
|