@rowsncolumns/rnc-yrs-store 0.30.1 → 0.31.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/dist/rnc_yrs_store.d.ts +358 -31
- package/dist/rnc_yrs_store.js +445 -29
- package/dist/rnc_yrs_store_bg.wasm +0 -0
- package/package.json +1 -1
package/dist/rnc_yrs_store.d.ts
CHANGED
|
@@ -1,6 +1,118 @@
|
|
|
1
1
|
/* tslint:disable */
|
|
2
2
|
/* eslint-disable */
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* One conversion of one room's state, and the ONE update that converts that room in place.
|
|
6
|
+
*
|
|
7
|
+
* ```text
|
|
8
|
+
* let c = InPlaceConversion::convert(&room_state, &options)?; // the room as read, whole
|
|
9
|
+
* let update = c.update()?; // store exactly this, once
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
12
|
+
* # The contract
|
|
13
|
+
*
|
|
14
|
+
* [`Self::update`], applied to the state this conversion was given, makes that document the
|
|
15
|
+
* converted one: it opens on the stable-ids store as a final room, reads cell for cell what the
|
|
16
|
+
* room read, and holds no live positional entry. It is one update: the converted document
|
|
17
|
+
* encoded against the state vector of the state read. The stamp, every final cell and the
|
|
18
|
+
* deletion of every positional entry are inside it, and nothing of the conversion is outside
|
|
19
|
+
* it. Store it as one update and never in parts: a rollback is built from the items of an
|
|
20
|
+
* update, and a part that held cells without the stamp could be rolled back on its own.
|
|
21
|
+
*
|
|
22
|
+
* The room plus the update is the converted document item for item (the same state vector, the
|
|
23
|
+
* same deletions, the same reads). It is not the same bytes: a document encoded whole again
|
|
24
|
+
* orders its values its own way.
|
|
25
|
+
*
|
|
26
|
+
* **One condition, which only the host can keep: the room has not changed since the state was
|
|
27
|
+
* read.** Merged into any other room, or into this room after a later write, the update is not
|
|
28
|
+
* supported: a cell typed in between stays a positional entry nobody reads, and a cell cleared
|
|
29
|
+
* in between comes back. So the host holds the room closed from the read to the write and
|
|
30
|
+
* makes the write conditional.
|
|
31
|
+
*
|
|
32
|
+
* **The condition is on the room's content, not on its state vector.** A deletion moves no
|
|
33
|
+
* state vector: a room that only lost a cell since the read has the state vector
|
|
34
|
+
* [`Self::state_vector`] answers, and this update would still put the cell back
|
|
35
|
+
* (`tests/in_place_conversion.rs` holds the case). The check has to cover deletions too.
|
|
36
|
+
*
|
|
37
|
+
* # The host's own writes
|
|
38
|
+
*
|
|
39
|
+
* A host that keeps data in the room beside the engine's (the anchors of the ranges it stores)
|
|
40
|
+
* writes it on top of [`Self::converted`], in a document of its own, and gives the update of
|
|
41
|
+
* what it wrote to [`Self::add_host_update`] before it takes [`Self::update`]. The one update
|
|
42
|
+
* then carries the host's writes too, so they are the conversion's and not somebody else's.
|
|
43
|
+
* What a first load of the converted copy writes can be added the same way.
|
|
44
|
+
*
|
|
45
|
+
* The conversion converts and cuts in one object and takes no converted copy from its caller:
|
|
46
|
+
* nothing can tell a copy made from an earlier read of the room from one made now when the room
|
|
47
|
+
* only lost a cell in between.
|
|
48
|
+
*/
|
|
49
|
+
export class InPlaceConversion {
|
|
50
|
+
free(): void;
|
|
51
|
+
[Symbol.dispose](): void;
|
|
52
|
+
/**
|
|
53
|
+
* Adds what the host wrote on top of `converted()` so `update()` carries it: the anchors of
|
|
54
|
+
* the ranges it stores in the room, or what a first load of the converted copy wrote. The
|
|
55
|
+
* host loads `converted()` into a document of its own, writes there, and passes the update
|
|
56
|
+
* of what it wrote (its document encoded against the state vector of `converted()`).
|
|
57
|
+
*
|
|
58
|
+
* Throws `invalid-host-update`: with nothing added, for bytes that are not a v1 update or
|
|
59
|
+
* an update cut against another document; and, for an update that changed the stamp, the
|
|
60
|
+
* marker or the room's own items, deleted what the room or the conversion wrote, wrote a
|
|
61
|
+
* positional cell, or wrote a hot value that is neither a cell record nor `null` (a string
|
|
62
|
+
* under `rncCells`), with this conversion answering no update from then on (convert
|
|
63
|
+
* again).
|
|
64
|
+
*/
|
|
65
|
+
addHostUpdate(update: Uint8Array): void;
|
|
66
|
+
/**
|
|
67
|
+
* The converted document's whole state as one v1 update, with every host update added so
|
|
68
|
+
* far. A document of its own: read it, compare it with the room, or write host data on top
|
|
69
|
+
* of it (`addHostUpdate`). Never store it into a room.
|
|
70
|
+
*/
|
|
71
|
+
converted(): Uint8Array;
|
|
72
|
+
/**
|
|
73
|
+
* Converts `roomState` (a room's whole state as one v1 update: a positional room, or a staff
|
|
74
|
+
* room stamped `"v5"`) to the final stable-ids format and keeps the converted document, to
|
|
75
|
+
* answer the ONE update that converts that room in place.
|
|
76
|
+
*
|
|
77
|
+
* `optionsJson` (optional): `{"extents": {"<sheetId>": {"rows": <n>, "columns": <n>}}}`, the
|
|
78
|
+
* lines to name beyond the data: the farthest corner of every range the host stores for a
|
|
79
|
+
* sheet. Every sheet is named at least as far as its data and as a born sheet's birth block
|
|
80
|
+
* (1,000 rows by 52 columns). Each line takes the client-0 id of its position
|
|
81
|
+
* (`position << 32`); an in-place conversion takes no line-id map.
|
|
82
|
+
*
|
|
83
|
+
* The contract of `update()`: applied to the state given here, it makes that document the
|
|
84
|
+
* converted one. It opens on the stable-ids store as a final room, reads cell for cell what
|
|
85
|
+
* the room read, holds no live positional entry, and is one update with the stamp inside
|
|
86
|
+
* it. Store it as one update, never in parts. The room plus the update equals `converted()`
|
|
87
|
+
* item for item (the same state vector, deletions and reads), not byte for byte.
|
|
88
|
+
*
|
|
89
|
+
* One condition, which only the host can keep: the room has not changed since the state was
|
|
90
|
+
* read. Hold the room closed from the read to the write and make the write conditional on
|
|
91
|
+
* the room's CONTENT, not on a state vector: a deletion moves no state vector, and an
|
|
92
|
+
* update stored into a room that only lost a cell since the read puts the cell back.
|
|
93
|
+
*
|
|
94
|
+
* Throws what `convertToStableIds` throws (`converted-differs` and `recalculated-differs`
|
|
95
|
+
* among them: the conversion checks that the converted room reads as the room read, as
|
|
96
|
+
* stored and after a recalculation of both, before it answers), and
|
|
97
|
+
* `invalid-options` for options that are not a map of that shape (an array is not one), a
|
|
98
|
+
* sheet key that is not an id spelled the one way (`"1"`, never `"01"`), a sheet named
|
|
99
|
+
* twice, an extent outside the grid, or an extent on a sheet the document does not hold.
|
|
100
|
+
* Call `free()` when done: the object holds the converted document.
|
|
101
|
+
*/
|
|
102
|
+
constructor(room_state: Uint8Array, options_json?: string | null);
|
|
103
|
+
/**
|
|
104
|
+
* The state vector of the room state this conversion read (a v1 state vector). It does not
|
|
105
|
+
* prove the room unchanged: a deletion moves no state vector (see the constructor).
|
|
106
|
+
*/
|
|
107
|
+
stateVector(): Uint8Array;
|
|
108
|
+
/**
|
|
109
|
+
* The ONE update to store into the room this conversion read (see the constructor): the
|
|
110
|
+
* converted document, with every host update added so far, encoded against that room's
|
|
111
|
+
* state vector. Throws after a host update that broke the converted room.
|
|
112
|
+
*/
|
|
113
|
+
update(): Uint8Array;
|
|
114
|
+
}
|
|
115
|
+
|
|
4
116
|
/**
|
|
5
117
|
* Thin wasm-bindgen shell over the engine router ([`DualEngine`]: the positional v3 store or the
|
|
6
118
|
* stable-ids v5 store, by document). Bytes cross as `Uint8Array` (`Vec<u8>`/`&[u8]`), results as
|
|
@@ -9,6 +121,13 @@
|
|
|
9
121
|
export class SpreadsheetEngine {
|
|
10
122
|
free(): void;
|
|
11
123
|
[Symbol.dispose](): void;
|
|
124
|
+
/**
|
|
125
|
+
* Registers a sheet. Throws, with nothing added, where the sheet cannot be added because
|
|
126
|
+
* of the room or the session: the room's format (`unsupported-cell-format` or
|
|
127
|
+
* `newer-format`, the code first, then the reason) or a sealed session (`session-sealed`),
|
|
128
|
+
* as an import and `loadDocument` throw. In the host's read-only mode it adds nothing and
|
|
129
|
+
* does not throw.
|
|
130
|
+
*/
|
|
12
131
|
addSheet(sheet_id: number, title: string): void;
|
|
13
132
|
/**
|
|
14
133
|
* Anchor a `GridRange` on `sheet_id`: an opaque string (base64 stable range) that
|
|
@@ -27,6 +146,9 @@ export class SpreadsheetEngine {
|
|
|
27
146
|
* to project + render. Split out of the old apply+project+commit so `useSpreadsheetEngine`'s collab
|
|
28
147
|
* bridge can drive applyUpdate→syncRemote without projecting twice. (`apply_remote_update` on the
|
|
29
148
|
* inner engine still does both in one call for the older bespoke/worker path.)
|
|
149
|
+
*
|
|
150
|
+
* Throws `session-sealed` (the code first, then the reason) on a sealed session
|
|
151
|
+
* (`sessionSealed()`), each time and whatever the bytes: a sealed session takes nothing.
|
|
30
152
|
*/
|
|
31
153
|
applyUpdate(bytes: Uint8Array): void;
|
|
32
154
|
/**
|
|
@@ -281,6 +403,12 @@ export class SpreadsheetEngine {
|
|
|
281
403
|
* caps). See [`YDocEngine::last_import_recalc_skipped`].
|
|
282
404
|
*/
|
|
283
405
|
lastImportRecalcSkipped(): boolean;
|
|
406
|
+
/**
|
|
407
|
+
* Whether the next sort of whole lines would be written as a permutation of line ids:
|
|
408
|
+
* what `setLinePermutationSorts` said, else the room's default (`false` in a room in the
|
|
409
|
+
* final format and in a positional room, `true` in a room stamped `"v5"`).
|
|
410
|
+
*/
|
|
411
|
+
linePermutationSorts(): boolean;
|
|
284
412
|
/**
|
|
285
413
|
* Catalog the workbook's sheets WITHOUT ingesting any cells — JSON
|
|
286
414
|
* `[{sheetId, index, name, hidden}]` in tab order. The first step of the sheet-scoped import
|
|
@@ -297,12 +425,16 @@ export class SpreadsheetEngine {
|
|
|
297
425
|
* Bulk-load a peer's full-state snapshot (`stateAsUpdate`) and rebuild the calc engine — the
|
|
298
426
|
* join/bootstrap path. Returns a `CommitResult` JSON of every loaded cell (render the restored
|
|
299
427
|
* document in one shot). Not echoed back to the transport.
|
|
428
|
+
*
|
|
429
|
+
* Throws `session-sealed` (the code first, then the reason) on a sealed session
|
|
430
|
+
* (`sessionSealed()`), each time and whatever the bytes: a sealed session takes nothing.
|
|
300
431
|
*/
|
|
301
432
|
loadFromUpdate(bytes: Uint8Array): string;
|
|
302
433
|
/**
|
|
303
434
|
* Load a full-state snapshot WITHOUT building the render commit — for hosts that already have
|
|
304
435
|
* the render projection (engine hydration for editing, the bulk-import worker). Skipping the
|
|
305
|
-
* 500k-cell snapshot serialization saves seconds on huge documents.
|
|
436
|
+
* 500k-cell snapshot serialization saves seconds on huge documents. Throws `session-sealed`
|
|
437
|
+
* on a sealed session, as `loadFromUpdate` does.
|
|
306
438
|
*/
|
|
307
439
|
loadFromUpdateQuiet(bytes: Uint8Array): void;
|
|
308
440
|
/**
|
|
@@ -391,6 +523,36 @@ export class SpreadsheetEngine {
|
|
|
391
523
|
* not arrived on this replica; a malformed anchor is an `Err`.
|
|
392
524
|
*/
|
|
393
525
|
resolveAnchor(anchor: string): string;
|
|
526
|
+
/**
|
|
527
|
+
* Why this session's document is a damaged room, as JSON, or `undefined` when it is not:
|
|
528
|
+
* `{"code": "room-damaged", "format": "v6" | "unknown", "message": …}`.
|
|
529
|
+
*
|
|
530
|
+
* A room is damaged when it holds a format key and its stamp and marker do not read as
|
|
531
|
+
* that key says: a final room (`sheetDataV3["v6"]` was written in it) whose
|
|
532
|
+
* `docMeta.sheetDataVersion` no longer reads `"v6"` or whose `sheet-format.cells` no
|
|
533
|
+
* longer reads 3. An entry written without sight of the room outranks them, a later write
|
|
534
|
+
* replaced them, or they were removed: in the room itself, or only in this session's copy
|
|
535
|
+
* of it (a device copy, a document its host merged in). The engine cannot tell the two
|
|
536
|
+
* apart, and answers the same for both.
|
|
537
|
+
*
|
|
538
|
+
* The session is NOT sealed, and opening the sheet again does not help: a fresh engine
|
|
539
|
+
* would meet the same room. It is read-only: every command is refused with `room-damaged`
|
|
540
|
+
* and the reason, and no other entry point writes. And it hands out nothing:
|
|
541
|
+
* `takePendingUpdates`, `encodeDiffV1` and `stateAsUpdate` answer the empty update while
|
|
542
|
+
* the room is damaged, since what this copy holds beyond the room may be what would
|
|
543
|
+
* damage the room for everyone. It goes on taking the room's updates, and this answers
|
|
544
|
+
* `undefined` again once a repair written over the stamp and the marker arrives. The
|
|
545
|
+
* commit of the load or the merge that left the room damaged carries `roomDamaged` (this
|
|
546
|
+
* object). A sealed session answers `sessionSealed()` instead.
|
|
547
|
+
*
|
|
548
|
+
* `unsentWrites` is how many writes of its own the session holds that it has not handed
|
|
549
|
+
* out (one per local transaction not yet taken with `takePendingUpdates`, plus an
|
|
550
|
+
* import's transactions since the state was last taken). They are in this session and
|
|
551
|
+
* nowhere else while the room is damaged, and a reload loses them: a host shows the
|
|
552
|
+
* number, holds the tab open as it does for unsynced edits, and takes them with
|
|
553
|
+
* `takePendingUpdates` once this answers `undefined` again.
|
|
554
|
+
*/
|
|
555
|
+
roomDamaged(): string | undefined;
|
|
394
556
|
/**
|
|
395
557
|
* JSON array of the sheet's row ids in grid order, as decimal strings.
|
|
396
558
|
*/
|
|
@@ -399,12 +561,87 @@ export class SpreadsheetEngine {
|
|
|
399
561
|
* The workbook's Scenario Manager records as a `SheetScenarios[]` JSON.
|
|
400
562
|
*/
|
|
401
563
|
scenarios(): string;
|
|
564
|
+
/**
|
|
565
|
+
* Why this session is sealed, as JSON, or `undefined` when it is not: `{"code":
|
|
566
|
+
* "session-sealed", "format": "v6" | "unknown" | …, "message": …, "unsentWrites": n,
|
|
567
|
+
* "unlistedWrites": m}`.
|
|
568
|
+
*
|
|
569
|
+
* A session is sealed when a room it must not write arrives (by `loadFromUpdate` or by a
|
|
570
|
+
* merge) while it holds something of its own: an item under its client id (a default
|
|
571
|
+
* sheet seeded before the room arrived, an edit), an update it has not handed out, or one
|
|
572
|
+
* it has. The rooms: one in the final format (`"v6"`), one stamped with a format this
|
|
573
|
+
* engine does not know, one whose marker this engine does not write. That is a tab whose
|
|
574
|
+
* copy predates the room's conversion, or a host that wrote before its room arrived.
|
|
575
|
+
*
|
|
576
|
+
* What the room is, is read from the session's document once the arrival is integrated,
|
|
577
|
+
* its format keys before its stamp and marker (`sheetFormat()`): the order and the
|
|
578
|
+
* packaging of what the session received do not change the answer, and no entry that
|
|
579
|
+
* outranks a final room's stamp, no later write over it and no removal of it makes a
|
|
580
|
+
* final room read as anything else.
|
|
581
|
+
*
|
|
582
|
+
* A sealed session is harmless and stays so: it writes nothing on any path, every command
|
|
583
|
+
* is refused with `session-sealed`, `takePendingUpdates`, `encodeDiffV1` and
|
|
584
|
+
* `stateAsUpdate` answer nothing of it (the empty update), it takes no more remote
|
|
585
|
+
* updates, and nothing in its document is rebuilt or repaired. `unconvertedWrites()` and
|
|
586
|
+
* `takeUnconvertedWrites()` list the positional writes it held that the room does not
|
|
587
|
+
* hold, for the host to show. The commit of the load or the merge that sealed it carries
|
|
588
|
+
* `sessionSealed` (this object). The host discards the engine and opens a fresh one,
|
|
589
|
+
* empty: a session that arrives holding nothing of its own is never sealed.
|
|
590
|
+
*
|
|
591
|
+
* That list holds positional cells, notes and line sizes only. So the seal counts what
|
|
592
|
+
* the session had not sent, and the counts stay after the list is taken:
|
|
593
|
+
* * `unsentWrites`: how many updates of its own the session had not handed out through
|
|
594
|
+
* `takePendingUpdates` when the room arrived. One per local transaction: an edit, an
|
|
595
|
+
* undo, a default sheet seeded with `addSheet`, a repair the engine made. (What a
|
|
596
|
+
* session wrote on the positional store before it moved to the stable-ids one is one
|
|
597
|
+
* update.) An import is not queued (its host sends it from `stateAsUpdate` or
|
|
598
|
+
* `encodeDiffV1`): each transaction it made counts until the host takes the state. An
|
|
599
|
+
* edit already handed out is not counted: the engine cannot tell whether it reached
|
|
600
|
+
* the room.
|
|
601
|
+
* * `unlistedWrites`: how many of those the list does not account for. Every update that
|
|
602
|
+
* did anything but write a positional cell, note or line size of a room that turned
|
|
603
|
+
* stable-ids: a stable-ids session's cells, a format, a row or column inserted or
|
|
604
|
+
* removed, a positional cell deleted outright (`delete-cells`: its key is gone, and
|
|
605
|
+
* there is nothing left to compare), a seeded sheet, an import. `0` says the list holds
|
|
606
|
+
* everything the session had not sent. Anything else: edits made in this session
|
|
607
|
+
* could not be listed, and the host says so.
|
|
608
|
+
*/
|
|
609
|
+
sessionSealed(): string | undefined;
|
|
402
610
|
/**
|
|
403
611
|
* The windows the host draws, JSON `[{sheetId, startRow, startCol, endRow, endCol}]` (1-based,
|
|
404
612
|
* inclusive — the `readWindow` shape; the buffered viewport plus frozen bands, say). `[]`
|
|
405
613
|
* clears them (commits whole again). Takes effect from the next commit.
|
|
406
614
|
*/
|
|
407
615
|
setCommitWindows(windows_json: string): void;
|
|
616
|
+
/**
|
|
617
|
+
* Create documents in the final format with this engine; off by default. On, the document
|
|
618
|
+
* this engine itself creates is born final: stamped `docMeta.sheetDataVersion = "v6"` in one
|
|
619
|
+
* transaction with `sheet-format.yjs = 14`, `sheet-format.cells = 3`, the inert key
|
|
620
|
+
* `sheetDataV3["v6"]` and each sheet's birth block, before its first data. That is the first
|
|
621
|
+
* edit, import or `loadDocument` of an engine that was never loaded from an update and never
|
|
622
|
+
* merged one. It implies stable ids for what the engine creates, whatever `setStableIds`
|
|
623
|
+
* says. A document the engine was handed is never made final by the setting: a room is final
|
|
624
|
+
* when it carries the stamp. `true` when the call made the document this engine is creating
|
|
625
|
+
* final. Nothing is born final unless the host turns this on.
|
|
626
|
+
*
|
|
627
|
+
* The document created this way is a room's first state: hand it out
|
|
628
|
+
* (`takePendingUpdates`, `stateAsUpdate` or `encodeDiffV1`) and make the room of it. A
|
|
629
|
+
* session that created one, handed none of it out, and is then handed a room (by
|
|
630
|
+
* `loadFromUpdate` or a merge that brings anything) is sealed (`sessionSealed()`): that
|
|
631
|
+
* room is not the one it created, and its stamp and birth block must not reach it. To
|
|
632
|
+
* open an existing room, load the room into an engine that holds nothing.
|
|
633
|
+
*/
|
|
634
|
+
setFinalFormat(enabled: boolean): boolean;
|
|
635
|
+
/**
|
|
636
|
+
* How this engine writes a sort of whole rows (or whole columns) on a stable-ids room:
|
|
637
|
+
* `true`, as a permutation of line ids (a small update; the rows keep their ids and move);
|
|
638
|
+
* `false`, as rewritten cells (what a positional room does). Without a call the room
|
|
639
|
+
* decides: **a room in the final format rewrites cells, a room stamped `"v5"` permutes.**
|
|
640
|
+
* The setting is this engine's and is not stored: every engine of a room should be given
|
|
641
|
+
* the same one. A sort that does not cover whole lines of data, and every sort on a
|
|
642
|
+
* positional room, rewrites cells whatever it says.
|
|
643
|
+
*/
|
|
644
|
+
setLinePermutationSorts(on: boolean): void;
|
|
408
645
|
/**
|
|
409
646
|
* Read-only mode, which the host sets from the room's grant: while on, the engine writes
|
|
410
647
|
* nothing to the document. Recalculations still run and show what they compute (a volatile
|
|
@@ -467,13 +704,48 @@ export class SpreadsheetEngine {
|
|
|
467
704
|
*/
|
|
468
705
|
sheetBackgroundImageUrl(sheet_id: number): string | undefined;
|
|
469
706
|
/**
|
|
470
|
-
* `"v5"` while the document runs on the stable-ids store, else `"v3"
|
|
707
|
+
* `"v5"` while the document runs on the stable-ids store, else `"v3"`: the store, not the
|
|
708
|
+
* format. A final room (stamped `"v6"`) runs on the stable-ids store and answers `"v5"`
|
|
709
|
+
* here; `sheetFormat()` tells the two apart.
|
|
471
710
|
*/
|
|
472
711
|
sheetDataVersion(): string;
|
|
473
712
|
/**
|
|
474
713
|
* Per-sheet 1-based data extents as JSON `[{"sheetId", "maxRow", "maxCol"}]`.
|
|
475
714
|
*/
|
|
476
715
|
sheetExtents(): string;
|
|
716
|
+
/**
|
|
717
|
+
* The format of the document: `"v6"` for a final room, `"v5"` for a room stamped `"v5"`,
|
|
718
|
+
* `"v3"` for a positional one, and `"unknown"` for a room this engine cannot place.
|
|
719
|
+
*
|
|
720
|
+
* A final room is known by its format key before its stamp. The final stamp writes
|
|
721
|
+
* `sheetDataV3["v6"]` first, before `docMeta.sheetDataVersion = "v6"` and
|
|
722
|
+
* `sheet-format.cells = 3`, in one transaction (a document that holds the stamp holds the
|
|
723
|
+
* key), and the item under a key cannot be unwritten, while the stamp and the marker can
|
|
724
|
+
* be outranked, written over or removed. So a document in which that key was ever written
|
|
725
|
+
* answers `"v6"` whatever its stamp and marker read now (`roomDamaged()` says when they do
|
|
726
|
+
* not read as a final room's, which includes the moment a stamp's entries are arriving
|
|
727
|
+
* apart), and one in which the key of a later format was ever written answers `"unknown"`.
|
|
728
|
+
*
|
|
729
|
+
* A document that holds neither key answers by the stamp and the marker it carries:
|
|
730
|
+
* `"v6"` when stamped `"v6"` with `sheet-format.cells = 3`, `"unknown"` when stamped
|
|
731
|
+
* `"v6"` without `cells = 3` or stamped with anything this engine does not list.
|
|
732
|
+
* Positional is no stamp, `"v2"`, `"v3"` or `"v4"`; the stamp is matched exactly, so
|
|
733
|
+
* `"v7"`, `"v1"`, `"V6"`, `"v6 "`, `"6"`, `""`, `null` and `6` are all unknown, as the
|
|
734
|
+
* hosts' own helper calls them.
|
|
735
|
+
*
|
|
736
|
+
* A `"v6"` room is read and written: its hot cells are JSON records and its formula text is
|
|
737
|
+
* rendered on read. Read-only here are an `"unknown"` room, a `"v6"` room whose row or
|
|
738
|
+
* column axis holds an element that is not a line id (`unsupported-axis-element`), a `"v5"`
|
|
739
|
+
* room whose `sheet-format.cells` is 2 or more, and a positional room whose `cells` is past
|
|
740
|
+
* 2: every command is refused (`unsupported-cell-format`, or `newer-format` for a stamp
|
|
741
|
+
* this engine does not know, with the reason in `rejections`), the entry points that are
|
|
742
|
+
* not commands write nothing (`addSheet`, an import, `loadDocument` and
|
|
743
|
+
* `declareExternalFunctions` throw the code and the reason), and the engine writes nothing
|
|
744
|
+
* on its own. A session that held something of its own when a final room or one of those
|
|
745
|
+
* rooms arrived (a default sheet seeded first, an unsent edit) is sealed:
|
|
746
|
+
* `sessionSealed()`.
|
|
747
|
+
*/
|
|
748
|
+
sheetFormat(): string;
|
|
477
749
|
/**
|
|
478
750
|
* The workbook's sheet ids in tab order (`SpreadsheetEngineLike.sheetIds()`).
|
|
479
751
|
*/
|
|
@@ -578,10 +850,12 @@ export class SpreadsheetEngine {
|
|
|
578
850
|
* The positional writes that were not in the v5 planes when this session moved to the
|
|
579
851
|
* stable-ids store: the session was on a v3 document and an update made it v5 (a conversion
|
|
580
852
|
* that had not read what this session wrote or received since). JSON array of
|
|
581
|
-
* `{kind: "cell" | "note" | "row" | "column", sheetId, rowIndex,
|
|
582
|
-
* formula?, written, current}`; the same list is on the commit the
|
|
583
|
-
* `unconvertedWrites`. Taken once (`"[]"` afterwards, and for a session
|
|
584
|
-
* The engine does not apply them: show them and let the person
|
|
853
|
+
* `{kind: "cell" | "note" | "row" | "column" | "format" | "merge", sheetId, rowIndex,
|
|
854
|
+
* columnIndex, value?, formula?, written, current}`; the same list is on the commit the
|
|
855
|
+
* move renders, as `unconvertedWrites`. Taken once (`"[]"` afterwards, and for a session
|
|
856
|
+
* that never moved). The engine does not apply them: show them and let the person
|
|
857
|
+
* re-apply. A later engine may list further kinds: skip or show a kind you do not know,
|
|
858
|
+
* do not fail on one.
|
|
585
859
|
*/
|
|
586
860
|
takeUnconvertedWrites(): string;
|
|
587
861
|
/**
|
|
@@ -596,6 +870,16 @@ export class SpreadsheetEngine {
|
|
|
596
870
|
* The same list read from the document as it is now, nothing taken: what a v5 document's
|
|
597
871
|
* positional planes hold that its v5 planes do not. `"[]"` after a conversion that read
|
|
598
872
|
* everything, and for a v3 document.
|
|
873
|
+
*
|
|
874
|
+
* In a FINAL room the list also holds what a positional writer left that the room does
|
|
875
|
+
* not read on two more planes: `"format"` (a positional format operation of the style
|
|
876
|
+
* log: `written` is the format it gives the cell at `rowIndex`, `columnIndex`, `current`
|
|
877
|
+
* the format the room reads there) and `"merge"` (a range of a sheet's positional merge
|
|
878
|
+
* list that is no merge of the room, at the range's first cell: `written` is the range,
|
|
879
|
+
* `current` the merge of the room it overlaps or `null`). A window that had not heard the
|
|
880
|
+
* room turn final wrote them; a positional row insert, column insert, delete or sort
|
|
881
|
+
* writes both for every format and merge it moves. A room stamped `"v5"` reads both where
|
|
882
|
+
* they stand and lists neither.
|
|
599
883
|
*/
|
|
600
884
|
unconvertedWrites(): string;
|
|
601
885
|
undo(): string;
|
|
@@ -635,37 +919,68 @@ export class YrsSheetDoc {
|
|
|
635
919
|
}
|
|
636
920
|
|
|
637
921
|
/**
|
|
638
|
-
* Converts a
|
|
922
|
+
* Converts a document to the final stable-ids format, outside any room.
|
|
639
923
|
*
|
|
640
|
-
* `
|
|
641
|
-
*
|
|
642
|
-
*
|
|
643
|
-
*
|
|
644
|
-
*
|
|
645
|
-
*
|
|
924
|
+
* `state` is the document's whole state as one v1 update (what `encodeStateAsUpdate` gives): a
|
|
925
|
+
* positional (v3) document, or a room stamped `"v5"`. The result is the converted document's
|
|
926
|
+
* whole state as one v1 update: a final room (`docMeta.sheetDataVersion = "v6"`,
|
|
927
|
+
* `sheet-format.cells = 3`) that reads, cell for cell and facet for facet, what the input read.
|
|
928
|
+
* Its cells are cold (column blocks) wherever a cell can be, its lines are named by explicit
|
|
929
|
+
* ids at least as far as a born sheet's birth block (1,000 rows by 52 columns), and the repairs
|
|
930
|
+
* a first load would make are already made. The result is a document of its own: read it, or
|
|
931
|
+
* copy content out of it. To convert a room in place use `InPlaceConversion`, never this
|
|
932
|
+
* function's bytes. Two conversions of the same input read the same; their bytes are not the
|
|
933
|
+
* same.
|
|
646
934
|
*
|
|
647
|
-
* Without `line_ids_json` (`undefined` or `null`) each line takes the client-0 id of its position
|
|
648
|
-
*
|
|
649
|
-
*
|
|
650
|
-
* ([`convert_to_stable_ids_with_line_ids`]): `{"freshClient": <1..=2^32-1>, "sheets":
|
|
935
|
+
* Without `line_ids_json` (`undefined` or `null`) each line takes the client-0 id of its position
|
|
936
|
+
* (`position << 32`). With it, each line takes the id the map gives its position and a fresh id
|
|
937
|
+
* `make_id(freshClient, n)` where it gives none: `{"freshClient": <1..=2^32-1>, "sheets":
|
|
651
938
|
* {"<sheetId>": {"rowIds": [<id> | null, …], "columnIds": [<id> | null, …]}}}`, an id as its
|
|
652
939
|
* decimal string (as `rowIds` / `columnIds` give them). A host restoring a version saved before its
|
|
653
940
|
* room was converted gives the room's ids to the lines the room still has, so a reference the room
|
|
654
941
|
* keeps on a line stays on that line, and fresh ids to the rest (a `freshClient` the room never
|
|
655
|
-
* used), so a reference never lands on another line.
|
|
942
|
+
* used), so a reference never lands on another line. With a map the sheets are named as far as
|
|
943
|
+
* their data and the map, not as far as the birth block.
|
|
656
944
|
*
|
|
657
945
|
* Throws, with no result, a message that starts with:
|
|
658
|
-
* * `already-stable-ids`: the input is already
|
|
659
|
-
*
|
|
660
|
-
* * `
|
|
946
|
+
* * `already-stable-ids`: the input is already in the final format (it holds the final
|
|
947
|
+
* format's key, whatever its stamp reads now, or is stamped `"v6"`);
|
|
948
|
+
* * `newer-format`: the input is of a data format after v6, by its format key or its stamp;
|
|
949
|
+
* * `migration-refused`: a `sheet-format.cells` the conversion does not take (past 2 on a
|
|
950
|
+
* positional room, 2 or more on a room stamped `"v5"`);
|
|
661
951
|
* * `invalid-document`: bytes that are not a v1 update, an update that is not a whole state, a
|
|
662
952
|
* document that holds no sheet and no cell, or a positional entry outside the grid;
|
|
663
|
-
* * `
|
|
664
|
-
*
|
|
665
|
-
*
|
|
666
|
-
*
|
|
953
|
+
* * `unreadable-entry`: an entry of a shape this engine cannot read, a size key in a spelling
|
|
954
|
+
* no build writes (`1:C:+5`, `1:R:07`), or two size entries that name one line;
|
|
955
|
+
* * `convert-failed`: the conversion would leave a positional entry out, a room stamped `"v5"`
|
|
956
|
+
* holds positional writes its planes do not hold, or the engine failed;
|
|
957
|
+
* * `table-and-name-clash`: a positional room holds a table and a workbook-scoped defined name
|
|
958
|
+
* under one name (the message names both); no conversion keeps what every formula reads;
|
|
959
|
+
* * `converted-differs`: the converted document does not read as the room read (every
|
|
960
|
+
* conversion loads both and compares the sheet list, the extents, the settings, every facet,
|
|
961
|
+
* the merges, the charts, every size, hidden flag and note, and every sheet's cells before
|
|
962
|
+
* it answers; the message names the first read that differs);
|
|
963
|
+
* * `recalculated-differs`: the two read the same as stored and no longer do once both are
|
|
964
|
+
* recalculated whole, which every conversion does, in engines of its own and at one instant
|
|
965
|
+
* (nothing it computes is stored in the result; no host function is asked). The message
|
|
966
|
+
* names the first cell that differs and which part of it. Count these apart: such a room
|
|
967
|
+
* holds a result that is out of date, or one the two stores compute differently;
|
|
968
|
+
* * `room-past-the-caps`: the room holds more than 4,000,000 cells or more than
|
|
969
|
+
* 200,000 formulas, past which this build does not fill its calc engine because the
|
|
970
|
+
* recalculation can exhaust its memory, so the conversion does not run its check here and
|
|
971
|
+
* refuses first. Convert such a room with the native converter (`rnc-native convert`),
|
|
972
|
+
* which has no cap;
|
|
973
|
+
* * `stored-result-changed`: a cell of the result stores a computed value the input's own
|
|
974
|
+
* bytes do not hold. The conversion computes none (a result converts as it is stored, a
|
|
975
|
+
* host function's answer included, and a formula with no stored result converts with
|
|
976
|
+
* none), so no room is expected to meet this: it is the last check;
|
|
977
|
+
* * `invalid-line-ids`: a map that is not the shape above (an array is not a map; a sheet key is
|
|
978
|
+
* its id spelled the one way, `"1"` and never `"01"`, and each sheet is named once), a fresh
|
|
979
|
+
* client of 0 or past 32 bits, an id that is no line id, an id of the fresh client, one id
|
|
980
|
+
* named twice on an axis, a sheet the document does not hold, or a sheet whose lines are
|
|
981
|
+
* already named.
|
|
667
982
|
*/
|
|
668
|
-
export function convertToStableIds(
|
|
983
|
+
export function convertToStableIds(state: Uint8Array, line_ids_json?: string | null): Uint8Array;
|
|
669
984
|
|
|
670
985
|
/**
|
|
671
986
|
* Engine-less resolution of a `GridRange` on `sheet_id` through an op list in application order
|
|
@@ -682,7 +997,7 @@ export interface InitOutput {
|
|
|
682
997
|
readonly memory: WebAssembly.Memory;
|
|
683
998
|
readonly __wbg_spreadsheetengine_free: (a: number, b: number) => void;
|
|
684
999
|
readonly __wbg_yrssheetdoc_free: (a: number, b: number) => void;
|
|
685
|
-
readonly spreadsheetengine_addSheet: (a: number, b: number, c: number, d: number) =>
|
|
1000
|
+
readonly spreadsheetengine_addSheet: (a: number, b: number, c: number, d: number) => [number, number];
|
|
686
1001
|
readonly spreadsheetengine_applyCommand: (a: number, b: number, c: number) => [number, number, number, number];
|
|
687
1002
|
readonly spreadsheetengine_applyCommandQuiet: (a: number, b: number, c: number) => [number, number];
|
|
688
1003
|
readonly spreadsheetengine_applyUpdate: (a: number, b: number, c: number) => [number, number];
|
|
@@ -728,6 +1043,7 @@ export interface InitOutput {
|
|
|
728
1043
|
readonly spreadsheetengine_isEncryptedXlsx: (a: number, b: number, c: number) => number;
|
|
729
1044
|
readonly spreadsheetengine_lastImportCounts: (a: number) => [number, number];
|
|
730
1045
|
readonly spreadsheetengine_lastImportRecalcSkipped: (a: number) => number;
|
|
1046
|
+
readonly spreadsheetengine_linePermutationSorts: (a: number) => number;
|
|
731
1047
|
readonly spreadsheetengine_listXlsxSheets: (a: number, b: number, c: number) => [number, number, number, number];
|
|
732
1048
|
readonly spreadsheetengine_loadDocument: (a: number, b: number, c: number) => [number, number, number, number];
|
|
733
1049
|
readonly spreadsheetengine_loadFromUpdate: (a: number, b: number, c: number) => [number, number, number, number];
|
|
@@ -746,8 +1062,12 @@ export interface InitOutput {
|
|
|
746
1062
|
readonly spreadsheetengine_redo: (a: number) => [number, number];
|
|
747
1063
|
readonly spreadsheetengine_redoDepth: (a: number) => number;
|
|
748
1064
|
readonly spreadsheetengine_registerCustomFunction: (a: number, b: number, c: number) => void;
|
|
1065
|
+
readonly spreadsheetengine_roomDamaged: (a: number) => [number, number];
|
|
749
1066
|
readonly spreadsheetengine_scenarios: (a: number) => [number, number];
|
|
1067
|
+
readonly spreadsheetengine_sessionSealed: (a: number) => [number, number];
|
|
750
1068
|
readonly spreadsheetengine_setCommitWindows: (a: number, b: number, c: number) => [number, number];
|
|
1069
|
+
readonly spreadsheetengine_setFinalFormat: (a: number, b: number) => [number, number, number];
|
|
1070
|
+
readonly spreadsheetengine_setLinePermutationSorts: (a: number, b: number) => void;
|
|
751
1071
|
readonly spreadsheetengine_setReadOnly: (a: number, b: number) => [number, number];
|
|
752
1072
|
readonly spreadsheetengine_setStableIds: (a: number, b: number) => [number, number, number];
|
|
753
1073
|
readonly spreadsheetengine_setTimezoneOffsetMinutes: (a: number, b: number) => number;
|
|
@@ -756,6 +1076,7 @@ export interface InitOutput {
|
|
|
756
1076
|
readonly spreadsheetengine_sheetBackgroundImageUrl: (a: number, b: number) => [number, number];
|
|
757
1077
|
readonly spreadsheetengine_sheetDataVersion: (a: number) => [number, number];
|
|
758
1078
|
readonly spreadsheetengine_sheetExtents: (a: number) => [number, number];
|
|
1079
|
+
readonly spreadsheetengine_sheetFormat: (a: number) => [number, number];
|
|
759
1080
|
readonly spreadsheetengine_sheetIds: (a: number) => [number, number];
|
|
760
1081
|
readonly spreadsheetengine_sheetMetas: (a: number) => [number, number];
|
|
761
1082
|
readonly spreadsheetengine_sheetStats: (a: number) => [number, number];
|
|
@@ -779,17 +1100,23 @@ export interface InitOutput {
|
|
|
779
1100
|
readonly yrssheetdoc_new: () => number;
|
|
780
1101
|
readonly yrssheetdoc_setCell: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number];
|
|
781
1102
|
readonly spreadsheetengine_stateAsUpdate: (a: number) => [number, number];
|
|
782
|
-
readonly
|
|
1103
|
+
readonly spreadsheetengine_anchorRange: (a: number, b: number, c: number, d: number) => [number, number, number, number];
|
|
783
1104
|
readonly spreadsheetengine_columnIds: (a: number, b: number) => [number, number];
|
|
784
1105
|
readonly spreadsheetengine_parseStableCellKey: (a: number, b: number, c: number) => [number, number];
|
|
785
1106
|
readonly spreadsheetengine_readForeignCell: (a: number, b: number, c: number, d: number, e: number) => [number, number, number, number];
|
|
786
|
-
readonly spreadsheetengine_rowIds: (a: number, b: number) => [number, number];
|
|
787
|
-
readonly spreadsheetengine_stableCellKey: (a: number, b: number, c: number, d: number) => [number, number];
|
|
788
|
-
readonly spreadsheetengine_anchorRange: (a: number, b: number, c: number, d: number) => [number, number, number, number];
|
|
789
1107
|
readonly spreadsheetengine_resolveAnchor: (a: number, b: number, c: number) => [number, number, number, number];
|
|
1108
|
+
readonly spreadsheetengine_rowIds: (a: number, b: number) => [number, number];
|
|
790
1109
|
readonly spreadsheetengine_shiftLogFrontier: (a: number) => [number, number];
|
|
1110
|
+
readonly spreadsheetengine_stableCellKey: (a: number, b: number, c: number, d: number) => [number, number];
|
|
791
1111
|
readonly spreadsheetengine_transformRange: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number, number];
|
|
792
1112
|
readonly transformRangeThroughOps: (a: number, b: number, c: number, d: number, e: number) => [number, number, number, number];
|
|
1113
|
+
readonly __wbg_inplaceconversion_free: (a: number, b: number) => void;
|
|
1114
|
+
readonly convertToStableIds: (a: number, b: number, c: number, d: number) => [number, number, number, number];
|
|
1115
|
+
readonly inplaceconversion_addHostUpdate: (a: number, b: number, c: number) => [number, number];
|
|
1116
|
+
readonly inplaceconversion_converted: (a: number) => [number, number];
|
|
1117
|
+
readonly inplaceconversion_new: (a: number, b: number, c: number, d: number) => [number, number, number];
|
|
1118
|
+
readonly inplaceconversion_stateVector: (a: number) => [number, number];
|
|
1119
|
+
readonly inplaceconversion_update: (a: number) => [number, number, number, number];
|
|
793
1120
|
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
794
1121
|
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
795
1122
|
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
|
package/dist/rnc_yrs_store.js
CHANGED
|
@@ -1,5 +1,169 @@
|
|
|
1
1
|
/* @ts-self-types="./rnc_yrs_store.d.ts" */
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* One conversion of one room's state, and the ONE update that converts that room in place.
|
|
5
|
+
*
|
|
6
|
+
* ```text
|
|
7
|
+
* let c = InPlaceConversion::convert(&room_state, &options)?; // the room as read, whole
|
|
8
|
+
* let update = c.update()?; // store exactly this, once
|
|
9
|
+
* ```
|
|
10
|
+
*
|
|
11
|
+
* # The contract
|
|
12
|
+
*
|
|
13
|
+
* [`Self::update`], applied to the state this conversion was given, makes that document the
|
|
14
|
+
* converted one: it opens on the stable-ids store as a final room, reads cell for cell what the
|
|
15
|
+
* room read, and holds no live positional entry. It is one update: the converted document
|
|
16
|
+
* encoded against the state vector of the state read. The stamp, every final cell and the
|
|
17
|
+
* deletion of every positional entry are inside it, and nothing of the conversion is outside
|
|
18
|
+
* it. Store it as one update and never in parts: a rollback is built from the items of an
|
|
19
|
+
* update, and a part that held cells without the stamp could be rolled back on its own.
|
|
20
|
+
*
|
|
21
|
+
* The room plus the update is the converted document item for item (the same state vector, the
|
|
22
|
+
* same deletions, the same reads). It is not the same bytes: a document encoded whole again
|
|
23
|
+
* orders its values its own way.
|
|
24
|
+
*
|
|
25
|
+
* **One condition, which only the host can keep: the room has not changed since the state was
|
|
26
|
+
* read.** Merged into any other room, or into this room after a later write, the update is not
|
|
27
|
+
* supported: a cell typed in between stays a positional entry nobody reads, and a cell cleared
|
|
28
|
+
* in between comes back. So the host holds the room closed from the read to the write and
|
|
29
|
+
* makes the write conditional.
|
|
30
|
+
*
|
|
31
|
+
* **The condition is on the room's content, not on its state vector.** A deletion moves no
|
|
32
|
+
* state vector: a room that only lost a cell since the read has the state vector
|
|
33
|
+
* [`Self::state_vector`] answers, and this update would still put the cell back
|
|
34
|
+
* (`tests/in_place_conversion.rs` holds the case). The check has to cover deletions too.
|
|
35
|
+
*
|
|
36
|
+
* # The host's own writes
|
|
37
|
+
*
|
|
38
|
+
* A host that keeps data in the room beside the engine's (the anchors of the ranges it stores)
|
|
39
|
+
* writes it on top of [`Self::converted`], in a document of its own, and gives the update of
|
|
40
|
+
* what it wrote to [`Self::add_host_update`] before it takes [`Self::update`]. The one update
|
|
41
|
+
* then carries the host's writes too, so they are the conversion's and not somebody else's.
|
|
42
|
+
* What a first load of the converted copy writes can be added the same way.
|
|
43
|
+
*
|
|
44
|
+
* The conversion converts and cuts in one object and takes no converted copy from its caller:
|
|
45
|
+
* nothing can tell a copy made from an earlier read of the room from one made now when the room
|
|
46
|
+
* only lost a cell in between.
|
|
47
|
+
*/
|
|
48
|
+
export class InPlaceConversion {
|
|
49
|
+
__destroy_into_raw() {
|
|
50
|
+
const ptr = this.__wbg_ptr;
|
|
51
|
+
this.__wbg_ptr = 0;
|
|
52
|
+
InPlaceConversionFinalization.unregister(this);
|
|
53
|
+
return ptr;
|
|
54
|
+
}
|
|
55
|
+
free() {
|
|
56
|
+
const ptr = this.__destroy_into_raw();
|
|
57
|
+
wasm.__wbg_inplaceconversion_free(ptr, 0);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Adds what the host wrote on top of `converted()` so `update()` carries it: the anchors of
|
|
61
|
+
* the ranges it stores in the room, or what a first load of the converted copy wrote. The
|
|
62
|
+
* host loads `converted()` into a document of its own, writes there, and passes the update
|
|
63
|
+
* of what it wrote (its document encoded against the state vector of `converted()`).
|
|
64
|
+
*
|
|
65
|
+
* Throws `invalid-host-update`: with nothing added, for bytes that are not a v1 update or
|
|
66
|
+
* an update cut against another document; and, for an update that changed the stamp, the
|
|
67
|
+
* marker or the room's own items, deleted what the room or the conversion wrote, wrote a
|
|
68
|
+
* positional cell, or wrote a hot value that is neither a cell record nor `null` (a string
|
|
69
|
+
* under `rncCells`), with this conversion answering no update from then on (convert
|
|
70
|
+
* again).
|
|
71
|
+
* @param {Uint8Array} update
|
|
72
|
+
*/
|
|
73
|
+
addHostUpdate(update) {
|
|
74
|
+
const ptr0 = passArray8ToWasm0(update, wasm.__wbindgen_malloc);
|
|
75
|
+
const len0 = WASM_VECTOR_LEN;
|
|
76
|
+
const ret = wasm.inplaceconversion_addHostUpdate(this.__wbg_ptr, ptr0, len0);
|
|
77
|
+
if (ret[1]) {
|
|
78
|
+
throw takeFromExternrefTable0(ret[0]);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* The converted document's whole state as one v1 update, with every host update added so
|
|
83
|
+
* far. A document of its own: read it, compare it with the room, or write host data on top
|
|
84
|
+
* of it (`addHostUpdate`). Never store it into a room.
|
|
85
|
+
* @returns {Uint8Array}
|
|
86
|
+
*/
|
|
87
|
+
converted() {
|
|
88
|
+
const ret = wasm.inplaceconversion_converted(this.__wbg_ptr);
|
|
89
|
+
var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
90
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
91
|
+
return v1;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Converts `roomState` (a room's whole state as one v1 update: a positional room, or a staff
|
|
95
|
+
* room stamped `"v5"`) to the final stable-ids format and keeps the converted document, to
|
|
96
|
+
* answer the ONE update that converts that room in place.
|
|
97
|
+
*
|
|
98
|
+
* `optionsJson` (optional): `{"extents": {"<sheetId>": {"rows": <n>, "columns": <n>}}}`, the
|
|
99
|
+
* lines to name beyond the data: the farthest corner of every range the host stores for a
|
|
100
|
+
* sheet. Every sheet is named at least as far as its data and as a born sheet's birth block
|
|
101
|
+
* (1,000 rows by 52 columns). Each line takes the client-0 id of its position
|
|
102
|
+
* (`position << 32`); an in-place conversion takes no line-id map.
|
|
103
|
+
*
|
|
104
|
+
* The contract of `update()`: applied to the state given here, it makes that document the
|
|
105
|
+
* converted one. It opens on the stable-ids store as a final room, reads cell for cell what
|
|
106
|
+
* the room read, holds no live positional entry, and is one update with the stamp inside
|
|
107
|
+
* it. Store it as one update, never in parts. The room plus the update equals `converted()`
|
|
108
|
+
* item for item (the same state vector, deletions and reads), not byte for byte.
|
|
109
|
+
*
|
|
110
|
+
* One condition, which only the host can keep: the room has not changed since the state was
|
|
111
|
+
* read. Hold the room closed from the read to the write and make the write conditional on
|
|
112
|
+
* the room's CONTENT, not on a state vector: a deletion moves no state vector, and an
|
|
113
|
+
* update stored into a room that only lost a cell since the read puts the cell back.
|
|
114
|
+
*
|
|
115
|
+
* Throws what `convertToStableIds` throws (`converted-differs` and `recalculated-differs`
|
|
116
|
+
* among them: the conversion checks that the converted room reads as the room read, as
|
|
117
|
+
* stored and after a recalculation of both, before it answers), and
|
|
118
|
+
* `invalid-options` for options that are not a map of that shape (an array is not one), a
|
|
119
|
+
* sheet key that is not an id spelled the one way (`"1"`, never `"01"`), a sheet named
|
|
120
|
+
* twice, an extent outside the grid, or an extent on a sheet the document does not hold.
|
|
121
|
+
* Call `free()` when done: the object holds the converted document.
|
|
122
|
+
* @param {Uint8Array} room_state
|
|
123
|
+
* @param {string | null} [options_json]
|
|
124
|
+
*/
|
|
125
|
+
constructor(room_state, options_json) {
|
|
126
|
+
const ptr0 = passArray8ToWasm0(room_state, wasm.__wbindgen_malloc);
|
|
127
|
+
const len0 = WASM_VECTOR_LEN;
|
|
128
|
+
var ptr1 = isLikeNone(options_json) ? 0 : passStringToWasm0(options_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
129
|
+
var len1 = WASM_VECTOR_LEN;
|
|
130
|
+
const ret = wasm.inplaceconversion_new(ptr0, len0, ptr1, len1);
|
|
131
|
+
if (ret[2]) {
|
|
132
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
133
|
+
}
|
|
134
|
+
this.__wbg_ptr = ret[0];
|
|
135
|
+
InPlaceConversionFinalization.register(this, this.__wbg_ptr, this);
|
|
136
|
+
return this;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* The state vector of the room state this conversion read (a v1 state vector). It does not
|
|
140
|
+
* prove the room unchanged: a deletion moves no state vector (see the constructor).
|
|
141
|
+
* @returns {Uint8Array}
|
|
142
|
+
*/
|
|
143
|
+
stateVector() {
|
|
144
|
+
const ret = wasm.inplaceconversion_stateVector(this.__wbg_ptr);
|
|
145
|
+
var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
146
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
147
|
+
return v1;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* The ONE update to store into the room this conversion read (see the constructor): the
|
|
151
|
+
* converted document, with every host update added so far, encoded against that room's
|
|
152
|
+
* state vector. Throws after a host update that broke the converted room.
|
|
153
|
+
* @returns {Uint8Array}
|
|
154
|
+
*/
|
|
155
|
+
update() {
|
|
156
|
+
const ret = wasm.inplaceconversion_update(this.__wbg_ptr);
|
|
157
|
+
if (ret[3]) {
|
|
158
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
159
|
+
}
|
|
160
|
+
var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
161
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
162
|
+
return v1;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
if (Symbol.dispose) InPlaceConversion.prototype[Symbol.dispose] = InPlaceConversion.prototype.free;
|
|
166
|
+
|
|
3
167
|
/**
|
|
4
168
|
* Thin wasm-bindgen shell over the engine router ([`DualEngine`]: the positional v3 store or the
|
|
5
169
|
* stable-ids v5 store, by document). Bytes cross as `Uint8Array` (`Vec<u8>`/`&[u8]`), results as
|
|
@@ -17,13 +181,21 @@ export class SpreadsheetEngine {
|
|
|
17
181
|
wasm.__wbg_spreadsheetengine_free(ptr, 0);
|
|
18
182
|
}
|
|
19
183
|
/**
|
|
184
|
+
* Registers a sheet. Throws, with nothing added, where the sheet cannot be added because
|
|
185
|
+
* of the room or the session: the room's format (`unsupported-cell-format` or
|
|
186
|
+
* `newer-format`, the code first, then the reason) or a sealed session (`session-sealed`),
|
|
187
|
+
* as an import and `loadDocument` throw. In the host's read-only mode it adds nothing and
|
|
188
|
+
* does not throw.
|
|
20
189
|
* @param {number} sheet_id
|
|
21
190
|
* @param {string} title
|
|
22
191
|
*/
|
|
23
192
|
addSheet(sheet_id, title) {
|
|
24
193
|
const ptr0 = passStringToWasm0(title, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
25
194
|
const len0 = WASM_VECTOR_LEN;
|
|
26
|
-
wasm.spreadsheetengine_addSheet(this.__wbg_ptr, sheet_id, ptr0, len0);
|
|
195
|
+
const ret = wasm.spreadsheetengine_addSheet(this.__wbg_ptr, sheet_id, ptr0, len0);
|
|
196
|
+
if (ret[1]) {
|
|
197
|
+
throw takeFromExternrefTable0(ret[0]);
|
|
198
|
+
}
|
|
27
199
|
}
|
|
28
200
|
/**
|
|
29
201
|
* Anchor a `GridRange` on `sheet_id`: an opaque string (base64 stable range) that
|
|
@@ -95,6 +267,9 @@ export class SpreadsheetEngine {
|
|
|
95
267
|
* to project + render. Split out of the old apply+project+commit so `useSpreadsheetEngine`'s collab
|
|
96
268
|
* bridge can drive applyUpdate→syncRemote without projecting twice. (`apply_remote_update` on the
|
|
97
269
|
* inner engine still does both in one call for the older bespoke/worker path.)
|
|
270
|
+
*
|
|
271
|
+
* Throws `session-sealed` (the code first, then the reason) on a sealed session
|
|
272
|
+
* (`sessionSealed()`), each time and whatever the bytes: a sealed session takes nothing.
|
|
98
273
|
* @param {Uint8Array} bytes
|
|
99
274
|
*/
|
|
100
275
|
applyUpdate(bytes) {
|
|
@@ -885,6 +1060,16 @@ export class SpreadsheetEngine {
|
|
|
885
1060
|
const ret = wasm.spreadsheetengine_lastImportRecalcSkipped(this.__wbg_ptr);
|
|
886
1061
|
return ret !== 0;
|
|
887
1062
|
}
|
|
1063
|
+
/**
|
|
1064
|
+
* Whether the next sort of whole lines would be written as a permutation of line ids:
|
|
1065
|
+
* what `setLinePermutationSorts` said, else the room's default (`false` in a room in the
|
|
1066
|
+
* final format and in a positional room, `true` in a room stamped `"v5"`).
|
|
1067
|
+
* @returns {boolean}
|
|
1068
|
+
*/
|
|
1069
|
+
linePermutationSorts() {
|
|
1070
|
+
const ret = wasm.spreadsheetengine_linePermutationSorts(this.__wbg_ptr);
|
|
1071
|
+
return ret !== 0;
|
|
1072
|
+
}
|
|
888
1073
|
/**
|
|
889
1074
|
* Catalog the workbook's sheets WITHOUT ingesting any cells — JSON
|
|
890
1075
|
* `[{sheetId, index, name, hidden}]` in tab order. The first step of the sheet-scoped import
|
|
@@ -943,6 +1128,9 @@ export class SpreadsheetEngine {
|
|
|
943
1128
|
* Bulk-load a peer's full-state snapshot (`stateAsUpdate`) and rebuild the calc engine — the
|
|
944
1129
|
* join/bootstrap path. Returns a `CommitResult` JSON of every loaded cell (render the restored
|
|
945
1130
|
* document in one shot). Not echoed back to the transport.
|
|
1131
|
+
*
|
|
1132
|
+
* Throws `session-sealed` (the code first, then the reason) on a sealed session
|
|
1133
|
+
* (`sessionSealed()`), each time and whatever the bytes: a sealed session takes nothing.
|
|
946
1134
|
* @param {Uint8Array} bytes
|
|
947
1135
|
* @returns {string}
|
|
948
1136
|
*/
|
|
@@ -969,7 +1157,8 @@ export class SpreadsheetEngine {
|
|
|
969
1157
|
/**
|
|
970
1158
|
* Load a full-state snapshot WITHOUT building the render commit — for hosts that already have
|
|
971
1159
|
* the render projection (engine hydration for editing, the bulk-import worker). Skipping the
|
|
972
|
-
* 500k-cell snapshot serialization saves seconds on huge documents.
|
|
1160
|
+
* 500k-cell snapshot serialization saves seconds on huge documents. Throws `session-sealed`
|
|
1161
|
+
* on a sealed session, as `loadFromUpdate` does.
|
|
973
1162
|
* @param {Uint8Array} bytes
|
|
974
1163
|
*/
|
|
975
1164
|
loadFromUpdateQuiet(bytes) {
|
|
@@ -1278,6 +1467,45 @@ export class SpreadsheetEngine {
|
|
|
1278
1467
|
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
|
|
1279
1468
|
}
|
|
1280
1469
|
}
|
|
1470
|
+
/**
|
|
1471
|
+
* Why this session's document is a damaged room, as JSON, or `undefined` when it is not:
|
|
1472
|
+
* `{"code": "room-damaged", "format": "v6" | "unknown", "message": …}`.
|
|
1473
|
+
*
|
|
1474
|
+
* A room is damaged when it holds a format key and its stamp and marker do not read as
|
|
1475
|
+
* that key says: a final room (`sheetDataV3["v6"]` was written in it) whose
|
|
1476
|
+
* `docMeta.sheetDataVersion` no longer reads `"v6"` or whose `sheet-format.cells` no
|
|
1477
|
+
* longer reads 3. An entry written without sight of the room outranks them, a later write
|
|
1478
|
+
* replaced them, or they were removed: in the room itself, or only in this session's copy
|
|
1479
|
+
* of it (a device copy, a document its host merged in). The engine cannot tell the two
|
|
1480
|
+
* apart, and answers the same for both.
|
|
1481
|
+
*
|
|
1482
|
+
* The session is NOT sealed, and opening the sheet again does not help: a fresh engine
|
|
1483
|
+
* would meet the same room. It is read-only: every command is refused with `room-damaged`
|
|
1484
|
+
* and the reason, and no other entry point writes. And it hands out nothing:
|
|
1485
|
+
* `takePendingUpdates`, `encodeDiffV1` and `stateAsUpdate` answer the empty update while
|
|
1486
|
+
* the room is damaged, since what this copy holds beyond the room may be what would
|
|
1487
|
+
* damage the room for everyone. It goes on taking the room's updates, and this answers
|
|
1488
|
+
* `undefined` again once a repair written over the stamp and the marker arrives. The
|
|
1489
|
+
* commit of the load or the merge that left the room damaged carries `roomDamaged` (this
|
|
1490
|
+
* object). A sealed session answers `sessionSealed()` instead.
|
|
1491
|
+
*
|
|
1492
|
+
* `unsentWrites` is how many writes of its own the session holds that it has not handed
|
|
1493
|
+
* out (one per local transaction not yet taken with `takePendingUpdates`, plus an
|
|
1494
|
+
* import's transactions since the state was last taken). They are in this session and
|
|
1495
|
+
* nowhere else while the room is damaged, and a reload loses them: a host shows the
|
|
1496
|
+
* number, holds the tab open as it does for unsynced edits, and takes them with
|
|
1497
|
+
* `takePendingUpdates` once this answers `undefined` again.
|
|
1498
|
+
* @returns {string | undefined}
|
|
1499
|
+
*/
|
|
1500
|
+
roomDamaged() {
|
|
1501
|
+
const ret = wasm.spreadsheetengine_roomDamaged(this.__wbg_ptr);
|
|
1502
|
+
let v1;
|
|
1503
|
+
if (ret[0] !== 0) {
|
|
1504
|
+
v1 = getStringFromWasm0(ret[0], ret[1]).slice();
|
|
1505
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
1506
|
+
}
|
|
1507
|
+
return v1;
|
|
1508
|
+
}
|
|
1281
1509
|
/**
|
|
1282
1510
|
* JSON array of the sheet's row ids in grid order, as decimal strings.
|
|
1283
1511
|
* @param {number} sheet_id
|
|
@@ -1311,6 +1539,61 @@ export class SpreadsheetEngine {
|
|
|
1311
1539
|
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
|
|
1312
1540
|
}
|
|
1313
1541
|
}
|
|
1542
|
+
/**
|
|
1543
|
+
* Why this session is sealed, as JSON, or `undefined` when it is not: `{"code":
|
|
1544
|
+
* "session-sealed", "format": "v6" | "unknown" | …, "message": …, "unsentWrites": n,
|
|
1545
|
+
* "unlistedWrites": m}`.
|
|
1546
|
+
*
|
|
1547
|
+
* A session is sealed when a room it must not write arrives (by `loadFromUpdate` or by a
|
|
1548
|
+
* merge) while it holds something of its own: an item under its client id (a default
|
|
1549
|
+
* sheet seeded before the room arrived, an edit), an update it has not handed out, or one
|
|
1550
|
+
* it has. The rooms: one in the final format (`"v6"`), one stamped with a format this
|
|
1551
|
+
* engine does not know, one whose marker this engine does not write. That is a tab whose
|
|
1552
|
+
* copy predates the room's conversion, or a host that wrote before its room arrived.
|
|
1553
|
+
*
|
|
1554
|
+
* What the room is, is read from the session's document once the arrival is integrated,
|
|
1555
|
+
* its format keys before its stamp and marker (`sheetFormat()`): the order and the
|
|
1556
|
+
* packaging of what the session received do not change the answer, and no entry that
|
|
1557
|
+
* outranks a final room's stamp, no later write over it and no removal of it makes a
|
|
1558
|
+
* final room read as anything else.
|
|
1559
|
+
*
|
|
1560
|
+
* A sealed session is harmless and stays so: it writes nothing on any path, every command
|
|
1561
|
+
* is refused with `session-sealed`, `takePendingUpdates`, `encodeDiffV1` and
|
|
1562
|
+
* `stateAsUpdate` answer nothing of it (the empty update), it takes no more remote
|
|
1563
|
+
* updates, and nothing in its document is rebuilt or repaired. `unconvertedWrites()` and
|
|
1564
|
+
* `takeUnconvertedWrites()` list the positional writes it held that the room does not
|
|
1565
|
+
* hold, for the host to show. The commit of the load or the merge that sealed it carries
|
|
1566
|
+
* `sessionSealed` (this object). The host discards the engine and opens a fresh one,
|
|
1567
|
+
* empty: a session that arrives holding nothing of its own is never sealed.
|
|
1568
|
+
*
|
|
1569
|
+
* That list holds positional cells, notes and line sizes only. So the seal counts what
|
|
1570
|
+
* the session had not sent, and the counts stay after the list is taken:
|
|
1571
|
+
* * `unsentWrites`: how many updates of its own the session had not handed out through
|
|
1572
|
+
* `takePendingUpdates` when the room arrived. One per local transaction: an edit, an
|
|
1573
|
+
* undo, a default sheet seeded with `addSheet`, a repair the engine made. (What a
|
|
1574
|
+
* session wrote on the positional store before it moved to the stable-ids one is one
|
|
1575
|
+
* update.) An import is not queued (its host sends it from `stateAsUpdate` or
|
|
1576
|
+
* `encodeDiffV1`): each transaction it made counts until the host takes the state. An
|
|
1577
|
+
* edit already handed out is not counted: the engine cannot tell whether it reached
|
|
1578
|
+
* the room.
|
|
1579
|
+
* * `unlistedWrites`: how many of those the list does not account for. Every update that
|
|
1580
|
+
* did anything but write a positional cell, note or line size of a room that turned
|
|
1581
|
+
* stable-ids: a stable-ids session's cells, a format, a row or column inserted or
|
|
1582
|
+
* removed, a positional cell deleted outright (`delete-cells`: its key is gone, and
|
|
1583
|
+
* there is nothing left to compare), a seeded sheet, an import. `0` says the list holds
|
|
1584
|
+
* everything the session had not sent. Anything else: edits made in this session
|
|
1585
|
+
* could not be listed, and the host says so.
|
|
1586
|
+
* @returns {string | undefined}
|
|
1587
|
+
*/
|
|
1588
|
+
sessionSealed() {
|
|
1589
|
+
const ret = wasm.spreadsheetengine_sessionSealed(this.__wbg_ptr);
|
|
1590
|
+
let v1;
|
|
1591
|
+
if (ret[0] !== 0) {
|
|
1592
|
+
v1 = getStringFromWasm0(ret[0], ret[1]).slice();
|
|
1593
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
1594
|
+
}
|
|
1595
|
+
return v1;
|
|
1596
|
+
}
|
|
1314
1597
|
/**
|
|
1315
1598
|
* The windows the host draws, JSON `[{sheetId, startRow, startCol, endRow, endCol}]` (1-based,
|
|
1316
1599
|
* inclusive — the `readWindow` shape; the buffered viewport plus frozen bands, say). `[]`
|
|
@@ -1325,6 +1608,46 @@ export class SpreadsheetEngine {
|
|
|
1325
1608
|
throw takeFromExternrefTable0(ret[0]);
|
|
1326
1609
|
}
|
|
1327
1610
|
}
|
|
1611
|
+
/**
|
|
1612
|
+
* Create documents in the final format with this engine; off by default. On, the document
|
|
1613
|
+
* this engine itself creates is born final: stamped `docMeta.sheetDataVersion = "v6"` in one
|
|
1614
|
+
* transaction with `sheet-format.yjs = 14`, `sheet-format.cells = 3`, the inert key
|
|
1615
|
+
* `sheetDataV3["v6"]` and each sheet's birth block, before its first data. That is the first
|
|
1616
|
+
* edit, import or `loadDocument` of an engine that was never loaded from an update and never
|
|
1617
|
+
* merged one. It implies stable ids for what the engine creates, whatever `setStableIds`
|
|
1618
|
+
* says. A document the engine was handed is never made final by the setting: a room is final
|
|
1619
|
+
* when it carries the stamp. `true` when the call made the document this engine is creating
|
|
1620
|
+
* final. Nothing is born final unless the host turns this on.
|
|
1621
|
+
*
|
|
1622
|
+
* The document created this way is a room's first state: hand it out
|
|
1623
|
+
* (`takePendingUpdates`, `stateAsUpdate` or `encodeDiffV1`) and make the room of it. A
|
|
1624
|
+
* session that created one, handed none of it out, and is then handed a room (by
|
|
1625
|
+
* `loadFromUpdate` or a merge that brings anything) is sealed (`sessionSealed()`): that
|
|
1626
|
+
* room is not the one it created, and its stamp and birth block must not reach it. To
|
|
1627
|
+
* open an existing room, load the room into an engine that holds nothing.
|
|
1628
|
+
* @param {boolean} enabled
|
|
1629
|
+
* @returns {boolean}
|
|
1630
|
+
*/
|
|
1631
|
+
setFinalFormat(enabled) {
|
|
1632
|
+
const ret = wasm.spreadsheetengine_setFinalFormat(this.__wbg_ptr, enabled);
|
|
1633
|
+
if (ret[2]) {
|
|
1634
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
1635
|
+
}
|
|
1636
|
+
return ret[0] !== 0;
|
|
1637
|
+
}
|
|
1638
|
+
/**
|
|
1639
|
+
* How this engine writes a sort of whole rows (or whole columns) on a stable-ids room:
|
|
1640
|
+
* `true`, as a permutation of line ids (a small update; the rows keep their ids and move);
|
|
1641
|
+
* `false`, as rewritten cells (what a positional room does). Without a call the room
|
|
1642
|
+
* decides: **a room in the final format rewrites cells, a room stamped `"v5"` permutes.**
|
|
1643
|
+
* The setting is this engine's and is not stored: every engine of a room should be given
|
|
1644
|
+
* the same one. A sort that does not cover whole lines of data, and every sort on a
|
|
1645
|
+
* positional room, rewrites cells whatever it says.
|
|
1646
|
+
* @param {boolean} on
|
|
1647
|
+
*/
|
|
1648
|
+
setLinePermutationSorts(on) {
|
|
1649
|
+
wasm.spreadsheetengine_setLinePermutationSorts(this.__wbg_ptr, on);
|
|
1650
|
+
}
|
|
1328
1651
|
/**
|
|
1329
1652
|
* Read-only mode, which the host sets from the room's grant: while on, the engine writes
|
|
1330
1653
|
* nothing to the document. Recalculations still run and show what they compute (a volatile
|
|
@@ -1431,7 +1754,9 @@ export class SpreadsheetEngine {
|
|
|
1431
1754
|
return v1;
|
|
1432
1755
|
}
|
|
1433
1756
|
/**
|
|
1434
|
-
* `"v5"` while the document runs on the stable-ids store, else `"v3"
|
|
1757
|
+
* `"v5"` while the document runs on the stable-ids store, else `"v3"`: the store, not the
|
|
1758
|
+
* format. A final room (stamped `"v6"`) runs on the stable-ids store and answers `"v5"`
|
|
1759
|
+
* here; `sheetFormat()` tells the two apart.
|
|
1435
1760
|
* @returns {string}
|
|
1436
1761
|
*/
|
|
1437
1762
|
sheetDataVersion() {
|
|
@@ -1462,6 +1787,51 @@ export class SpreadsheetEngine {
|
|
|
1462
1787
|
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
|
|
1463
1788
|
}
|
|
1464
1789
|
}
|
|
1790
|
+
/**
|
|
1791
|
+
* The format of the document: `"v6"` for a final room, `"v5"` for a room stamped `"v5"`,
|
|
1792
|
+
* `"v3"` for a positional one, and `"unknown"` for a room this engine cannot place.
|
|
1793
|
+
*
|
|
1794
|
+
* A final room is known by its format key before its stamp. The final stamp writes
|
|
1795
|
+
* `sheetDataV3["v6"]` first, before `docMeta.sheetDataVersion = "v6"` and
|
|
1796
|
+
* `sheet-format.cells = 3`, in one transaction (a document that holds the stamp holds the
|
|
1797
|
+
* key), and the item under a key cannot be unwritten, while the stamp and the marker can
|
|
1798
|
+
* be outranked, written over or removed. So a document in which that key was ever written
|
|
1799
|
+
* answers `"v6"` whatever its stamp and marker read now (`roomDamaged()` says when they do
|
|
1800
|
+
* not read as a final room's, which includes the moment a stamp's entries are arriving
|
|
1801
|
+
* apart), and one in which the key of a later format was ever written answers `"unknown"`.
|
|
1802
|
+
*
|
|
1803
|
+
* A document that holds neither key answers by the stamp and the marker it carries:
|
|
1804
|
+
* `"v6"` when stamped `"v6"` with `sheet-format.cells = 3`, `"unknown"` when stamped
|
|
1805
|
+
* `"v6"` without `cells = 3` or stamped with anything this engine does not list.
|
|
1806
|
+
* Positional is no stamp, `"v2"`, `"v3"` or `"v4"`; the stamp is matched exactly, so
|
|
1807
|
+
* `"v7"`, `"v1"`, `"V6"`, `"v6 "`, `"6"`, `""`, `null` and `6` are all unknown, as the
|
|
1808
|
+
* hosts' own helper calls them.
|
|
1809
|
+
*
|
|
1810
|
+
* A `"v6"` room is read and written: its hot cells are JSON records and its formula text is
|
|
1811
|
+
* rendered on read. Read-only here are an `"unknown"` room, a `"v6"` room whose row or
|
|
1812
|
+
* column axis holds an element that is not a line id (`unsupported-axis-element`), a `"v5"`
|
|
1813
|
+
* room whose `sheet-format.cells` is 2 or more, and a positional room whose `cells` is past
|
|
1814
|
+
* 2: every command is refused (`unsupported-cell-format`, or `newer-format` for a stamp
|
|
1815
|
+
* this engine does not know, with the reason in `rejections`), the entry points that are
|
|
1816
|
+
* not commands write nothing (`addSheet`, an import, `loadDocument` and
|
|
1817
|
+
* `declareExternalFunctions` throw the code and the reason), and the engine writes nothing
|
|
1818
|
+
* on its own. A session that held something of its own when a final room or one of those
|
|
1819
|
+
* rooms arrived (a default sheet seeded first, an unsent edit) is sealed:
|
|
1820
|
+
* `sessionSealed()`.
|
|
1821
|
+
* @returns {string}
|
|
1822
|
+
*/
|
|
1823
|
+
sheetFormat() {
|
|
1824
|
+
let deferred1_0;
|
|
1825
|
+
let deferred1_1;
|
|
1826
|
+
try {
|
|
1827
|
+
const ret = wasm.spreadsheetengine_sheetFormat(this.__wbg_ptr);
|
|
1828
|
+
deferred1_0 = ret[0];
|
|
1829
|
+
deferred1_1 = ret[1];
|
|
1830
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
1831
|
+
} finally {
|
|
1832
|
+
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
|
|
1833
|
+
}
|
|
1834
|
+
}
|
|
1465
1835
|
/**
|
|
1466
1836
|
* The workbook's sheet ids in tab order (`SpreadsheetEngineLike.sheetIds()`).
|
|
1467
1837
|
* @returns {Int32Array}
|
|
@@ -1719,10 +2089,12 @@ export class SpreadsheetEngine {
|
|
|
1719
2089
|
* The positional writes that were not in the v5 planes when this session moved to the
|
|
1720
2090
|
* stable-ids store: the session was on a v3 document and an update made it v5 (a conversion
|
|
1721
2091
|
* that had not read what this session wrote or received since). JSON array of
|
|
1722
|
-
* `{kind: "cell" | "note" | "row" | "column", sheetId, rowIndex,
|
|
1723
|
-
* formula?, written, current}`; the same list is on the commit the
|
|
1724
|
-
* `unconvertedWrites`. Taken once (`"[]"` afterwards, and for a session
|
|
1725
|
-
* The engine does not apply them: show them and let the person
|
|
2092
|
+
* `{kind: "cell" | "note" | "row" | "column" | "format" | "merge", sheetId, rowIndex,
|
|
2093
|
+
* columnIndex, value?, formula?, written, current}`; the same list is on the commit the
|
|
2094
|
+
* move renders, as `unconvertedWrites`. Taken once (`"[]"` afterwards, and for a session
|
|
2095
|
+
* that never moved). The engine does not apply them: show them and let the person
|
|
2096
|
+
* re-apply. A later engine may list further kinds: skip or show a kind you do not know,
|
|
2097
|
+
* do not fail on one.
|
|
1726
2098
|
* @returns {string}
|
|
1727
2099
|
*/
|
|
1728
2100
|
takeUnconvertedWrites() {
|
|
@@ -1774,6 +2146,16 @@ export class SpreadsheetEngine {
|
|
|
1774
2146
|
* The same list read from the document as it is now, nothing taken: what a v5 document's
|
|
1775
2147
|
* positional planes hold that its v5 planes do not. `"[]"` after a conversion that read
|
|
1776
2148
|
* everything, and for a v3 document.
|
|
2149
|
+
*
|
|
2150
|
+
* In a FINAL room the list also holds what a positional writer left that the room does
|
|
2151
|
+
* not read on two more planes: `"format"` (a positional format operation of the style
|
|
2152
|
+
* log: `written` is the format it gives the cell at `rowIndex`, `columnIndex`, `current`
|
|
2153
|
+
* the format the room reads there) and `"merge"` (a range of a sheet's positional merge
|
|
2154
|
+
* list that is no merge of the room, at the range's first cell: `written` is the range,
|
|
2155
|
+
* `current` the merge of the room it overlaps or `null`). A window that had not heard the
|
|
2156
|
+
* room turn final wrote them; a positional row insert, column insert, delete or sort
|
|
2157
|
+
* writes both for every format and merge it moves. A room stamped `"v5"` reads both where
|
|
2158
|
+
* they stand and lists neither.
|
|
1777
2159
|
* @returns {string}
|
|
1778
2160
|
*/
|
|
1779
2161
|
unconvertedWrites() {
|
|
@@ -1929,41 +2311,72 @@ export class YrsSheetDoc {
|
|
|
1929
2311
|
if (Symbol.dispose) YrsSheetDoc.prototype[Symbol.dispose] = YrsSheetDoc.prototype.free;
|
|
1930
2312
|
|
|
1931
2313
|
/**
|
|
1932
|
-
* Converts a
|
|
2314
|
+
* Converts a document to the final stable-ids format, outside any room.
|
|
1933
2315
|
*
|
|
1934
|
-
* `
|
|
1935
|
-
*
|
|
1936
|
-
*
|
|
1937
|
-
*
|
|
1938
|
-
*
|
|
1939
|
-
*
|
|
2316
|
+
* `state` is the document's whole state as one v1 update (what `encodeStateAsUpdate` gives): a
|
|
2317
|
+
* positional (v3) document, or a room stamped `"v5"`. The result is the converted document's
|
|
2318
|
+
* whole state as one v1 update: a final room (`docMeta.sheetDataVersion = "v6"`,
|
|
2319
|
+
* `sheet-format.cells = 3`) that reads, cell for cell and facet for facet, what the input read.
|
|
2320
|
+
* Its cells are cold (column blocks) wherever a cell can be, its lines are named by explicit
|
|
2321
|
+
* ids at least as far as a born sheet's birth block (1,000 rows by 52 columns), and the repairs
|
|
2322
|
+
* a first load would make are already made. The result is a document of its own: read it, or
|
|
2323
|
+
* copy content out of it. To convert a room in place use `InPlaceConversion`, never this
|
|
2324
|
+
* function's bytes. Two conversions of the same input read the same; their bytes are not the
|
|
2325
|
+
* same.
|
|
1940
2326
|
*
|
|
1941
|
-
* Without `line_ids_json` (`undefined` or `null`) each line takes the client-0 id of its position
|
|
1942
|
-
*
|
|
1943
|
-
*
|
|
1944
|
-
* ([`convert_to_stable_ids_with_line_ids`]): `{"freshClient": <1..=2^32-1>, "sheets":
|
|
2327
|
+
* Without `line_ids_json` (`undefined` or `null`) each line takes the client-0 id of its position
|
|
2328
|
+
* (`position << 32`). With it, each line takes the id the map gives its position and a fresh id
|
|
2329
|
+
* `make_id(freshClient, n)` where it gives none: `{"freshClient": <1..=2^32-1>, "sheets":
|
|
1945
2330
|
* {"<sheetId>": {"rowIds": [<id> | null, …], "columnIds": [<id> | null, …]}}}`, an id as its
|
|
1946
2331
|
* decimal string (as `rowIds` / `columnIds` give them). A host restoring a version saved before its
|
|
1947
2332
|
* room was converted gives the room's ids to the lines the room still has, so a reference the room
|
|
1948
2333
|
* keeps on a line stays on that line, and fresh ids to the rest (a `freshClient` the room never
|
|
1949
|
-
* used), so a reference never lands on another line.
|
|
2334
|
+
* used), so a reference never lands on another line. With a map the sheets are named as far as
|
|
2335
|
+
* their data and the map, not as far as the birth block.
|
|
1950
2336
|
*
|
|
1951
2337
|
* Throws, with no result, a message that starts with:
|
|
1952
|
-
* * `already-stable-ids`: the input is already
|
|
1953
|
-
*
|
|
1954
|
-
* * `
|
|
2338
|
+
* * `already-stable-ids`: the input is already in the final format (it holds the final
|
|
2339
|
+
* format's key, whatever its stamp reads now, or is stamped `"v6"`);
|
|
2340
|
+
* * `newer-format`: the input is of a data format after v6, by its format key or its stamp;
|
|
2341
|
+
* * `migration-refused`: a `sheet-format.cells` the conversion does not take (past 2 on a
|
|
2342
|
+
* positional room, 2 or more on a room stamped `"v5"`);
|
|
1955
2343
|
* * `invalid-document`: bytes that are not a v1 update, an update that is not a whole state, a
|
|
1956
2344
|
* document that holds no sheet and no cell, or a positional entry outside the grid;
|
|
1957
|
-
* * `
|
|
1958
|
-
*
|
|
1959
|
-
*
|
|
1960
|
-
*
|
|
1961
|
-
*
|
|
2345
|
+
* * `unreadable-entry`: an entry of a shape this engine cannot read, a size key in a spelling
|
|
2346
|
+
* no build writes (`1:C:+5`, `1:R:07`), or two size entries that name one line;
|
|
2347
|
+
* * `convert-failed`: the conversion would leave a positional entry out, a room stamped `"v5"`
|
|
2348
|
+
* holds positional writes its planes do not hold, or the engine failed;
|
|
2349
|
+
* * `table-and-name-clash`: a positional room holds a table and a workbook-scoped defined name
|
|
2350
|
+
* under one name (the message names both); no conversion keeps what every formula reads;
|
|
2351
|
+
* * `converted-differs`: the converted document does not read as the room read (every
|
|
2352
|
+
* conversion loads both and compares the sheet list, the extents, the settings, every facet,
|
|
2353
|
+
* the merges, the charts, every size, hidden flag and note, and every sheet's cells before
|
|
2354
|
+
* it answers; the message names the first read that differs);
|
|
2355
|
+
* * `recalculated-differs`: the two read the same as stored and no longer do once both are
|
|
2356
|
+
* recalculated whole, which every conversion does, in engines of its own and at one instant
|
|
2357
|
+
* (nothing it computes is stored in the result; no host function is asked). The message
|
|
2358
|
+
* names the first cell that differs and which part of it. Count these apart: such a room
|
|
2359
|
+
* holds a result that is out of date, or one the two stores compute differently;
|
|
2360
|
+
* * `room-past-the-caps`: the room holds more than 4,000,000 cells or more than
|
|
2361
|
+
* 200,000 formulas, past which this build does not fill its calc engine because the
|
|
2362
|
+
* recalculation can exhaust its memory, so the conversion does not run its check here and
|
|
2363
|
+
* refuses first. Convert such a room with the native converter (`rnc-native convert`),
|
|
2364
|
+
* which has no cap;
|
|
2365
|
+
* * `stored-result-changed`: a cell of the result stores a computed value the input's own
|
|
2366
|
+
* bytes do not hold. The conversion computes none (a result converts as it is stored, a
|
|
2367
|
+
* host function's answer included, and a formula with no stored result converts with
|
|
2368
|
+
* none), so no room is expected to meet this: it is the last check;
|
|
2369
|
+
* * `invalid-line-ids`: a map that is not the shape above (an array is not a map; a sheet key is
|
|
2370
|
+
* its id spelled the one way, `"1"` and never `"01"`, and each sheet is named once), a fresh
|
|
2371
|
+
* client of 0 or past 32 bits, an id that is no line id, an id of the fresh client, one id
|
|
2372
|
+
* named twice on an axis, a sheet the document does not hold, or a sheet whose lines are
|
|
2373
|
+
* already named.
|
|
2374
|
+
* @param {Uint8Array} state
|
|
1962
2375
|
* @param {string | null} [line_ids_json]
|
|
1963
2376
|
* @returns {Uint8Array}
|
|
1964
2377
|
*/
|
|
1965
|
-
export function convertToStableIds(
|
|
1966
|
-
const ptr0 = passArray8ToWasm0(
|
|
2378
|
+
export function convertToStableIds(state, line_ids_json) {
|
|
2379
|
+
const ptr0 = passArray8ToWasm0(state, wasm.__wbindgen_malloc);
|
|
1967
2380
|
const len0 = WASM_VECTOR_LEN;
|
|
1968
2381
|
var ptr1 = isLikeNone(line_ids_json) ? 0 : passStringToWasm0(line_ids_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
1969
2382
|
var len1 = WASM_VECTOR_LEN;
|
|
@@ -2122,6 +2535,9 @@ function __wbg_get_imports() {
|
|
|
2122
2535
|
};
|
|
2123
2536
|
}
|
|
2124
2537
|
|
|
2538
|
+
const InPlaceConversionFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
2539
|
+
? { register: () => {}, unregister: () => {} }
|
|
2540
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_inplaceconversion_free(ptr, 1));
|
|
2125
2541
|
const SpreadsheetEngineFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
2126
2542
|
? { register: () => {}, unregister: () => {} }
|
|
2127
2543
|
: new FinalizationRegistry(ptr => wasm.__wbg_spreadsheetengine_free(ptr, 1));
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rowsncolumns/rnc-yrs-store",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.31.0",
|
|
4
4
|
"author": "Vinay M",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
6
6
|
"description": "Document-backed Rust→WASM spreadsheet calc engine (yrs/CRDT, canonical sheetDataV3). Ships the `SpreadsheetEngine` (a `Store<YrsStore>`): applyCommand / undo / redo / canUndo + the Yjs collaboration surface (applyUpdate / takePendingUpdates / loadFromUpdate / stateAsUpdate) the Keryx update-pump binds to. This is the 1,000,000-row engine the demo-app ships today — previously vendored, now a versioned package. The PREBUILT wasm is included (consumers need NO Rust/wasm toolchain); the glue's default init REQUIRES an explicit `module_or_path` — pass the URL of the served `rnc_yrs_store_bg.wasm` (webpack/Turbopack statically resolve a bundled `new URL`, which would 404 from this package, so the inline-default branch is intentionally a throw).",
|