@rowsncolumns/rnc-yrs-store 0.30.0 → 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 +371 -31
- package/dist/rnc_yrs_store.js +481 -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
|
/**
|
|
@@ -330,6 +462,18 @@ export class SpreadsheetEngine {
|
|
|
330
462
|
* sheet registry is non-empty and contains no `sheetId: 1`. Returns `true` when pruned.
|
|
331
463
|
*/
|
|
332
464
|
pruneDanglingDefaultSeed(): boolean;
|
|
465
|
+
/**
|
|
466
|
+
* The record another replica holds under an `rncCells` key, as it reads on this engine's
|
|
467
|
+
* rows and columns: JSON `{sheetId, row, col, cell: {ue, ev, fv, ..} | null, derived}`,
|
|
468
|
+
* or `{"status":"gone"}` when a row or column of the key was deleted here.
|
|
469
|
+
* `foreign` is the other replica's whole state (`encodeStateAsUpdate`); a diff throws.
|
|
470
|
+
* Read-only: this engine's document is not changed. `cell` is `null` when the replica
|
|
471
|
+
* holds no typed record under the key (nothing typed, or cleared); `derived` says
|
|
472
|
+
* the engine wrote the record (a result, a formula's rewrite), not a person. The formula
|
|
473
|
+
* is rendered on this engine's lines and names; the result is the replica's own. Throws on
|
|
474
|
+
* a document that is not stable-ids.
|
|
475
|
+
*/
|
|
476
|
+
readForeignCell(foreign: Uint8Array, key: string): string;
|
|
333
477
|
/**
|
|
334
478
|
* Whether read-only mode is on (`setReadOnly`).
|
|
335
479
|
*/
|
|
@@ -379,6 +523,36 @@ export class SpreadsheetEngine {
|
|
|
379
523
|
* not arrived on this replica; a malformed anchor is an `Err`.
|
|
380
524
|
*/
|
|
381
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;
|
|
382
556
|
/**
|
|
383
557
|
* JSON array of the sheet's row ids in grid order, as decimal strings.
|
|
384
558
|
*/
|
|
@@ -387,12 +561,87 @@ export class SpreadsheetEngine {
|
|
|
387
561
|
* The workbook's Scenario Manager records as a `SheetScenarios[]` JSON.
|
|
388
562
|
*/
|
|
389
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;
|
|
390
610
|
/**
|
|
391
611
|
* The windows the host draws, JSON `[{sheetId, startRow, startCol, endRow, endCol}]` (1-based,
|
|
392
612
|
* inclusive — the `readWindow` shape; the buffered viewport plus frozen bands, say). `[]`
|
|
393
613
|
* clears them (commits whole again). Takes effect from the next commit.
|
|
394
614
|
*/
|
|
395
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;
|
|
396
645
|
/**
|
|
397
646
|
* Read-only mode, which the host sets from the room's grant: while on, the engine writes
|
|
398
647
|
* nothing to the document. Recalculations still run and show what they compute (a volatile
|
|
@@ -455,13 +704,48 @@ export class SpreadsheetEngine {
|
|
|
455
704
|
*/
|
|
456
705
|
sheetBackgroundImageUrl(sheet_id: number): string | undefined;
|
|
457
706
|
/**
|
|
458
|
-
* `"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.
|
|
459
710
|
*/
|
|
460
711
|
sheetDataVersion(): string;
|
|
461
712
|
/**
|
|
462
713
|
* Per-sheet 1-based data extents as JSON `[{"sheetId", "maxRow", "maxCol"}]`.
|
|
463
714
|
*/
|
|
464
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;
|
|
465
749
|
/**
|
|
466
750
|
* The workbook's sheet ids in tab order (`SpreadsheetEngineLike.sheetIds()`).
|
|
467
751
|
*/
|
|
@@ -566,10 +850,12 @@ export class SpreadsheetEngine {
|
|
|
566
850
|
* The positional writes that were not in the v5 planes when this session moved to the
|
|
567
851
|
* stable-ids store: the session was on a v3 document and an update made it v5 (a conversion
|
|
568
852
|
* that had not read what this session wrote or received since). JSON array of
|
|
569
|
-
* `{kind: "cell" | "note" | "row" | "column", sheetId, rowIndex,
|
|
570
|
-
* formula?, written, current}`; the same list is on the commit the
|
|
571
|
-
* `unconvertedWrites`. Taken once (`"[]"` afterwards, and for a session
|
|
572
|
-
* 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.
|
|
573
859
|
*/
|
|
574
860
|
takeUnconvertedWrites(): string;
|
|
575
861
|
/**
|
|
@@ -584,6 +870,16 @@ export class SpreadsheetEngine {
|
|
|
584
870
|
* The same list read from the document as it is now, nothing taken: what a v5 document's
|
|
585
871
|
* positional planes hold that its v5 planes do not. `"[]"` after a conversion that read
|
|
586
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.
|
|
587
883
|
*/
|
|
588
884
|
unconvertedWrites(): string;
|
|
589
885
|
undo(): string;
|
|
@@ -623,37 +919,68 @@ export class YrsSheetDoc {
|
|
|
623
919
|
}
|
|
624
920
|
|
|
625
921
|
/**
|
|
626
|
-
* Converts a
|
|
922
|
+
* Converts a document to the final stable-ids format, outside any room.
|
|
627
923
|
*
|
|
628
|
-
* `
|
|
629
|
-
*
|
|
630
|
-
*
|
|
631
|
-
*
|
|
632
|
-
*
|
|
633
|
-
*
|
|
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.
|
|
634
934
|
*
|
|
635
|
-
* Without `line_ids_json` (`undefined` or `null`) each line takes the client-0 id of its position
|
|
636
|
-
*
|
|
637
|
-
*
|
|
638
|
-
* ([`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":
|
|
639
938
|
* {"<sheetId>": {"rowIds": [<id> | null, …], "columnIds": [<id> | null, …]}}}`, an id as its
|
|
640
939
|
* decimal string (as `rowIds` / `columnIds` give them). A host restoring a version saved before its
|
|
641
940
|
* room was converted gives the room's ids to the lines the room still has, so a reference the room
|
|
642
941
|
* keeps on a line stays on that line, and fresh ids to the rest (a `freshClient` the room never
|
|
643
|
-
* 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.
|
|
644
944
|
*
|
|
645
945
|
* Throws, with no result, a message that starts with:
|
|
646
|
-
* * `already-stable-ids`: the input is already
|
|
647
|
-
*
|
|
648
|
-
* * `
|
|
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"`);
|
|
649
951
|
* * `invalid-document`: bytes that are not a v1 update, an update that is not a whole state, a
|
|
650
952
|
* document that holds no sheet and no cell, or a positional entry outside the grid;
|
|
651
|
-
* * `
|
|
652
|
-
*
|
|
653
|
-
*
|
|
654
|
-
*
|
|
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.
|
|
655
982
|
*/
|
|
656
|
-
export function convertToStableIds(
|
|
983
|
+
export function convertToStableIds(state: Uint8Array, line_ids_json?: string | null): Uint8Array;
|
|
657
984
|
|
|
658
985
|
/**
|
|
659
986
|
* Engine-less resolution of a `GridRange` on `sheet_id` through an op list in application order
|
|
@@ -670,7 +997,7 @@ export interface InitOutput {
|
|
|
670
997
|
readonly memory: WebAssembly.Memory;
|
|
671
998
|
readonly __wbg_spreadsheetengine_free: (a: number, b: number) => void;
|
|
672
999
|
readonly __wbg_yrssheetdoc_free: (a: number, b: number) => void;
|
|
673
|
-
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];
|
|
674
1001
|
readonly spreadsheetengine_applyCommand: (a: number, b: number, c: number) => [number, number, number, number];
|
|
675
1002
|
readonly spreadsheetengine_applyCommandQuiet: (a: number, b: number, c: number) => [number, number];
|
|
676
1003
|
readonly spreadsheetengine_applyUpdate: (a: number, b: number, c: number) => [number, number];
|
|
@@ -716,6 +1043,7 @@ export interface InitOutput {
|
|
|
716
1043
|
readonly spreadsheetengine_isEncryptedXlsx: (a: number, b: number, c: number) => number;
|
|
717
1044
|
readonly spreadsheetengine_lastImportCounts: (a: number) => [number, number];
|
|
718
1045
|
readonly spreadsheetengine_lastImportRecalcSkipped: (a: number) => number;
|
|
1046
|
+
readonly spreadsheetengine_linePermutationSorts: (a: number) => number;
|
|
719
1047
|
readonly spreadsheetengine_listXlsxSheets: (a: number, b: number, c: number) => [number, number, number, number];
|
|
720
1048
|
readonly spreadsheetengine_loadDocument: (a: number, b: number, c: number) => [number, number, number, number];
|
|
721
1049
|
readonly spreadsheetengine_loadFromUpdate: (a: number, b: number, c: number) => [number, number, number, number];
|
|
@@ -734,8 +1062,12 @@ export interface InitOutput {
|
|
|
734
1062
|
readonly spreadsheetengine_redo: (a: number) => [number, number];
|
|
735
1063
|
readonly spreadsheetengine_redoDepth: (a: number) => number;
|
|
736
1064
|
readonly spreadsheetengine_registerCustomFunction: (a: number, b: number, c: number) => void;
|
|
1065
|
+
readonly spreadsheetengine_roomDamaged: (a: number) => [number, number];
|
|
737
1066
|
readonly spreadsheetengine_scenarios: (a: number) => [number, number];
|
|
1067
|
+
readonly spreadsheetengine_sessionSealed: (a: number) => [number, number];
|
|
738
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;
|
|
739
1071
|
readonly spreadsheetengine_setReadOnly: (a: number, b: number) => [number, number];
|
|
740
1072
|
readonly spreadsheetengine_setStableIds: (a: number, b: number) => [number, number, number];
|
|
741
1073
|
readonly spreadsheetengine_setTimezoneOffsetMinutes: (a: number, b: number) => number;
|
|
@@ -744,6 +1076,7 @@ export interface InitOutput {
|
|
|
744
1076
|
readonly spreadsheetengine_sheetBackgroundImageUrl: (a: number, b: number) => [number, number];
|
|
745
1077
|
readonly spreadsheetengine_sheetDataVersion: (a: number) => [number, number];
|
|
746
1078
|
readonly spreadsheetengine_sheetExtents: (a: number) => [number, number];
|
|
1079
|
+
readonly spreadsheetengine_sheetFormat: (a: number) => [number, number];
|
|
747
1080
|
readonly spreadsheetengine_sheetIds: (a: number) => [number, number];
|
|
748
1081
|
readonly spreadsheetengine_sheetMetas: (a: number) => [number, number];
|
|
749
1082
|
readonly spreadsheetengine_sheetStats: (a: number) => [number, number];
|
|
@@ -767,16 +1100,23 @@ export interface InitOutput {
|
|
|
767
1100
|
readonly yrssheetdoc_new: () => number;
|
|
768
1101
|
readonly yrssheetdoc_setCell: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number];
|
|
769
1102
|
readonly spreadsheetengine_stateAsUpdate: (a: number) => [number, number];
|
|
770
|
-
readonly
|
|
1103
|
+
readonly spreadsheetengine_anchorRange: (a: number, b: number, c: number, d: number) => [number, number, number, number];
|
|
771
1104
|
readonly spreadsheetengine_columnIds: (a: number, b: number) => [number, number];
|
|
772
1105
|
readonly spreadsheetengine_parseStableCellKey: (a: number, b: number, c: number) => [number, number];
|
|
773
|
-
readonly
|
|
774
|
-
readonly spreadsheetengine_stableCellKey: (a: number, b: number, c: number, d: number) => [number, number];
|
|
775
|
-
readonly spreadsheetengine_anchorRange: (a: number, b: number, c: number, d: number) => [number, number, number, number];
|
|
1106
|
+
readonly spreadsheetengine_readForeignCell: (a: number, b: number, c: number, d: number, e: number) => [number, number, number, number];
|
|
776
1107
|
readonly spreadsheetengine_resolveAnchor: (a: number, b: number, c: number) => [number, number, number, number];
|
|
1108
|
+
readonly spreadsheetengine_rowIds: (a: number, b: number) => [number, number];
|
|
777
1109
|
readonly spreadsheetengine_shiftLogFrontier: (a: number) => [number, number];
|
|
1110
|
+
readonly spreadsheetengine_stableCellKey: (a: number, b: number, c: number, d: number) => [number, number];
|
|
778
1111
|
readonly spreadsheetengine_transformRange: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number, number];
|
|
779
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];
|
|
780
1120
|
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
781
1121
|
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
782
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) {
|
|
@@ -1076,6 +1265,42 @@ export class SpreadsheetEngine {
|
|
|
1076
1265
|
const ret = wasm.spreadsheetengine_pruneDanglingDefaultSeed(this.__wbg_ptr);
|
|
1077
1266
|
return ret !== 0;
|
|
1078
1267
|
}
|
|
1268
|
+
/**
|
|
1269
|
+
* The record another replica holds under an `rncCells` key, as it reads on this engine's
|
|
1270
|
+
* rows and columns: JSON `{sheetId, row, col, cell: {ue, ev, fv, ..} | null, derived}`,
|
|
1271
|
+
* or `{"status":"gone"}` when a row or column of the key was deleted here.
|
|
1272
|
+
* `foreign` is the other replica's whole state (`encodeStateAsUpdate`); a diff throws.
|
|
1273
|
+
* Read-only: this engine's document is not changed. `cell` is `null` when the replica
|
|
1274
|
+
* holds no typed record under the key (nothing typed, or cleared); `derived` says
|
|
1275
|
+
* the engine wrote the record (a result, a formula's rewrite), not a person. The formula
|
|
1276
|
+
* is rendered on this engine's lines and names; the result is the replica's own. Throws on
|
|
1277
|
+
* a document that is not stable-ids.
|
|
1278
|
+
* @param {Uint8Array} foreign
|
|
1279
|
+
* @param {string} key
|
|
1280
|
+
* @returns {string}
|
|
1281
|
+
*/
|
|
1282
|
+
readForeignCell(foreign, key) {
|
|
1283
|
+
let deferred4_0;
|
|
1284
|
+
let deferred4_1;
|
|
1285
|
+
try {
|
|
1286
|
+
const ptr0 = passArray8ToWasm0(foreign, wasm.__wbindgen_malloc);
|
|
1287
|
+
const len0 = WASM_VECTOR_LEN;
|
|
1288
|
+
const ptr1 = passStringToWasm0(key, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
1289
|
+
const len1 = WASM_VECTOR_LEN;
|
|
1290
|
+
const ret = wasm.spreadsheetengine_readForeignCell(this.__wbg_ptr, ptr0, len0, ptr1, len1);
|
|
1291
|
+
var ptr3 = ret[0];
|
|
1292
|
+
var len3 = ret[1];
|
|
1293
|
+
if (ret[3]) {
|
|
1294
|
+
ptr3 = 0; len3 = 0;
|
|
1295
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
1296
|
+
}
|
|
1297
|
+
deferred4_0 = ptr3;
|
|
1298
|
+
deferred4_1 = len3;
|
|
1299
|
+
return getStringFromWasm0(ptr3, len3);
|
|
1300
|
+
} finally {
|
|
1301
|
+
wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
|
|
1302
|
+
}
|
|
1303
|
+
}
|
|
1079
1304
|
/**
|
|
1080
1305
|
* Whether read-only mode is on (`setReadOnly`).
|
|
1081
1306
|
* @returns {boolean}
|
|
@@ -1242,6 +1467,45 @@ export class SpreadsheetEngine {
|
|
|
1242
1467
|
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
|
|
1243
1468
|
}
|
|
1244
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
|
+
}
|
|
1245
1509
|
/**
|
|
1246
1510
|
* JSON array of the sheet's row ids in grid order, as decimal strings.
|
|
1247
1511
|
* @param {number} sheet_id
|
|
@@ -1275,6 +1539,61 @@ export class SpreadsheetEngine {
|
|
|
1275
1539
|
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
|
|
1276
1540
|
}
|
|
1277
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
|
+
}
|
|
1278
1597
|
/**
|
|
1279
1598
|
* The windows the host draws, JSON `[{sheetId, startRow, startCol, endRow, endCol}]` (1-based,
|
|
1280
1599
|
* inclusive — the `readWindow` shape; the buffered viewport plus frozen bands, say). `[]`
|
|
@@ -1289,6 +1608,46 @@ export class SpreadsheetEngine {
|
|
|
1289
1608
|
throw takeFromExternrefTable0(ret[0]);
|
|
1290
1609
|
}
|
|
1291
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
|
+
}
|
|
1292
1651
|
/**
|
|
1293
1652
|
* Read-only mode, which the host sets from the room's grant: while on, the engine writes
|
|
1294
1653
|
* nothing to the document. Recalculations still run and show what they compute (a volatile
|
|
@@ -1395,7 +1754,9 @@ export class SpreadsheetEngine {
|
|
|
1395
1754
|
return v1;
|
|
1396
1755
|
}
|
|
1397
1756
|
/**
|
|
1398
|
-
* `"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.
|
|
1399
1760
|
* @returns {string}
|
|
1400
1761
|
*/
|
|
1401
1762
|
sheetDataVersion() {
|
|
@@ -1426,6 +1787,51 @@ export class SpreadsheetEngine {
|
|
|
1426
1787
|
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
|
|
1427
1788
|
}
|
|
1428
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
|
+
}
|
|
1429
1835
|
/**
|
|
1430
1836
|
* The workbook's sheet ids in tab order (`SpreadsheetEngineLike.sheetIds()`).
|
|
1431
1837
|
* @returns {Int32Array}
|
|
@@ -1683,10 +2089,12 @@ export class SpreadsheetEngine {
|
|
|
1683
2089
|
* The positional writes that were not in the v5 planes when this session moved to the
|
|
1684
2090
|
* stable-ids store: the session was on a v3 document and an update made it v5 (a conversion
|
|
1685
2091
|
* that had not read what this session wrote or received since). JSON array of
|
|
1686
|
-
* `{kind: "cell" | "note" | "row" | "column", sheetId, rowIndex,
|
|
1687
|
-
* formula?, written, current}`; the same list is on the commit the
|
|
1688
|
-
* `unconvertedWrites`. Taken once (`"[]"` afterwards, and for a session
|
|
1689
|
-
* 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.
|
|
1690
2098
|
* @returns {string}
|
|
1691
2099
|
*/
|
|
1692
2100
|
takeUnconvertedWrites() {
|
|
@@ -1738,6 +2146,16 @@ export class SpreadsheetEngine {
|
|
|
1738
2146
|
* The same list read from the document as it is now, nothing taken: what a v5 document's
|
|
1739
2147
|
* positional planes hold that its v5 planes do not. `"[]"` after a conversion that read
|
|
1740
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.
|
|
1741
2159
|
* @returns {string}
|
|
1742
2160
|
*/
|
|
1743
2161
|
unconvertedWrites() {
|
|
@@ -1893,41 +2311,72 @@ export class YrsSheetDoc {
|
|
|
1893
2311
|
if (Symbol.dispose) YrsSheetDoc.prototype[Symbol.dispose] = YrsSheetDoc.prototype.free;
|
|
1894
2312
|
|
|
1895
2313
|
/**
|
|
1896
|
-
* Converts a
|
|
2314
|
+
* Converts a document to the final stable-ids format, outside any room.
|
|
1897
2315
|
*
|
|
1898
|
-
* `
|
|
1899
|
-
*
|
|
1900
|
-
*
|
|
1901
|
-
*
|
|
1902
|
-
*
|
|
1903
|
-
*
|
|
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.
|
|
1904
2326
|
*
|
|
1905
|
-
* Without `line_ids_json` (`undefined` or `null`) each line takes the client-0 id of its position
|
|
1906
|
-
*
|
|
1907
|
-
*
|
|
1908
|
-
* ([`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":
|
|
1909
2330
|
* {"<sheetId>": {"rowIds": [<id> | null, …], "columnIds": [<id> | null, …]}}}`, an id as its
|
|
1910
2331
|
* decimal string (as `rowIds` / `columnIds` give them). A host restoring a version saved before its
|
|
1911
2332
|
* room was converted gives the room's ids to the lines the room still has, so a reference the room
|
|
1912
2333
|
* keeps on a line stays on that line, and fresh ids to the rest (a `freshClient` the room never
|
|
1913
|
-
* 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.
|
|
1914
2336
|
*
|
|
1915
2337
|
* Throws, with no result, a message that starts with:
|
|
1916
|
-
* * `already-stable-ids`: the input is already
|
|
1917
|
-
*
|
|
1918
|
-
* * `
|
|
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"`);
|
|
1919
2343
|
* * `invalid-document`: bytes that are not a v1 update, an update that is not a whole state, a
|
|
1920
2344
|
* document that holds no sheet and no cell, or a positional entry outside the grid;
|
|
1921
|
-
* * `
|
|
1922
|
-
*
|
|
1923
|
-
*
|
|
1924
|
-
*
|
|
1925
|
-
*
|
|
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
|
|
1926
2375
|
* @param {string | null} [line_ids_json]
|
|
1927
2376
|
* @returns {Uint8Array}
|
|
1928
2377
|
*/
|
|
1929
|
-
export function convertToStableIds(
|
|
1930
|
-
const ptr0 = passArray8ToWasm0(
|
|
2378
|
+
export function convertToStableIds(state, line_ids_json) {
|
|
2379
|
+
const ptr0 = passArray8ToWasm0(state, wasm.__wbindgen_malloc);
|
|
1931
2380
|
const len0 = WASM_VECTOR_LEN;
|
|
1932
2381
|
var ptr1 = isLikeNone(line_ids_json) ? 0 : passStringToWasm0(line_ids_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
1933
2382
|
var len1 = WASM_VECTOR_LEN;
|
|
@@ -2086,6 +2535,9 @@ function __wbg_get_imports() {
|
|
|
2086
2535
|
};
|
|
2087
2536
|
}
|
|
2088
2537
|
|
|
2538
|
+
const InPlaceConversionFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
2539
|
+
? { register: () => {}, unregister: () => {} }
|
|
2540
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_inplaceconversion_free(ptr, 1));
|
|
2089
2541
|
const SpreadsheetEngineFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
2090
2542
|
? { register: () => {}, unregister: () => {} }
|
|
2091
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).",
|