Commit graph

179 commits

Author SHA1 Message Date
Zixuan Chen
08390cb0de
chore: loro-crdt v0.8.0 2024-01-05 16:11:09 +08:00
Leon Zhao
76e3f97ff9
feat: use string as peer type in wasm (#234) 2024-01-05 12:06:13 +08:00
Zixuan Chen
bc27a47531
feat: stabilizing encoding (#219)
This PR implements a new encode schema that is more extendible and more compact. It’s also simpler and takes less binary size and maintaining effort. It is inspired by the [Automerge Encoding Format](https://automerge.org/automerge-binary-format-spec/).

The main motivation is the extensibility. When we integrate a new CRDT algorithm, we don’t want to make a breaking change to the encoding or keep multiple versions of the encoding schema in the code, as it will make our WASM size much larger. We need a stable and extendible encoding schema for our v1.0 version.

This PR also exposes the ops that compose the current container state. For example, now you can make a query about which operation a certain character quickly. This behavior is required in the new snapshot encoding, so it’s included in this PR.

# Encoding Schema

## Header

The header has 22 bytes.

- (0-4 bytes) Magic Bytes: The encoding starts with `loro` as magic bytes.
- (4-20 bytes) Checksum: MD5 checksum of the encoded data, including the header starting from 20th bytes. The checksum is encoded as a 16-byte array. The `checksum` and `magic bytes` fields are trimmed when calculating the checksum.
- (20-21 bytes) Encoding Method (2 bytes, big endian): Multiple encoding methods are available for a specific encoding version.

## Encode Mode: Updates

In this approach, only ops, specifically their historical record, are encoded, while document states are excluded.

Like Automerge's format, we employ columnar encoding for operations and changes.

Previously, operations were ordered by their Operation ID (OpId) before columnar encoding. However, sorting operations based on their respective containers initially enhance compression potential.

## Encode Mode: Snapshot

This mode simultaneously captures document state and historical data. Upon importing a snapshot into a new document, initialization occurs directly from the snapshot, bypassing the need for CRDT-based recalculations.

Unlike previous snapshot encoding methods, the current binary output in snapshot mode is compatible with the updates mode. This enhances the efficiency of importing snapshots into non-empty documents, where initialization via snapshot is infeasible. 

Additionally, when feasible, we leverage the sequence of operations to construct state snapshots. In CRDTs, deducing the specific ops constituting the current container state is feasible. These ops are tagged in relation to the container, facilitating direct state reconstruction from them. This approach, pioneered by Automerge, significantly improves compression efficiency.
2024-01-02 17:03:24 +08:00
Zixuan Chen
9477717e3e
chore: bump loro-crdt versions to v0.7.1 2023-12-26 18:01:14 +08:00
Zixuan Chen
612745aa8c
Fix issue with richtext's applyDelta() behavior (#226)
* fix: [LORO-371] The behavior of richtext's `applyDelta()` is not entirely correct #225

* test: add corresponding test

Fixes #225
2023-12-21 11:40:39 +08:00
Zixuan Chen
c2877e8468
chore: bump version 2023-12-14 10:38:54 +08:00
Leon zhao
442f2561a1
Remove prelim feature (#215)
* chore: remove prelim temporarily
2023-12-13 10:25:00 +08:00
Zixuan Chen
546cadf26c
refactor(wasm): invoke setPanicHook when starting 2023-12-08 16:58:41 +08:00
Zixuan Chen
ce36f8adbd
chore: bump version 2023-12-07 15:27:22 +08:00
Zixuan Chen
b689f5b1cd
chore: bump version 2023-12-06 23:39:55 +08:00
Zixuan Chen
ab64881029
fix: text tracker error #211 (#212)
* fix: text tracker error #211

* chore: rm only

* fix: refine
2023-12-06 23:36:21 +08:00
Zixuan Chen
4112a28607
chore: bump loro-crdt 2023-12-05 14:53:01 +08:00
Zixuan Chen
14c66edcd4
fix: use Object.getPrototypeOf instead of __proto__ 2023-12-05 14:51:31 +08:00
Zixuan Chen
aa87a96286
chore: bump loro-crdt js 2023-12-05 14:31:06 +08:00
Zixuan Chen
d9d28ada61
fix: refine isContainer & getType 2023-12-05 14:28:39 +08:00
Zixuan Chen
bbf8acd767
chore: bump version 2023-12-05 13:58:00 +08:00
Zixuan Chen
e4814aa627
chore: init changesets 2023-12-05 13:38:09 +08:00
Leon zhao
47fea50dda
Refactor: use ValueOrContainer for diff event (#202)
* feat: use resolved diff as event

* feat: wasm ValueOrContainer event

* fix: cargo fix

* fix: avoid state clone

* chore: add resolve event bench

* test: add handler in event test

* refactor: use resolved as external diff

* chore: cargo fix

* fix: typescript loro value type

* fix: use Arc::new_cyclic

* refactor: bring back sub container
2023-12-05 11:57:41 +08:00
Zixuan Chen
bf1a792933
refactor: only need shared ref on loro doc now (#203) 2023-12-03 14:54:45 +08:00
Leon zhao
afc4bfaf62
feat: tree rust api (#194) 2023-11-28 21:32:04 +08:00
Zixuan Chen
8b6f49f3b3
chore(release): 0.5.0 2023-11-27 17:56:04 +08:00
Zixuan Chen
88218c10bd
(WASM )Refactor wasm interfaces on List and Map (#192)
* refactor: refine wasm interfaces

* docs: update wasm doc
2023-11-27 17:53:02 +08:00
Zixuan Chen
e23ef4362d
fix: keep strong ref to doc in handlers #190 (#191) 2023-11-27 14:09:04 +08:00
Zixuan Chen
8e901cf00c
fix: #181 importing should use inherent arena
otherwise, txn, oplog and app state may use different
arena.
2023-11-21 20:29:01 +08:00
Zixuan Chen
826e7fdcb3
test: add import via frontiers test 2023-11-20 17:44:24 +08:00
Zixuan Chen
b940214985
fix: from snapshot should enable auto commit 2023-11-17 23:05:20 +08:00
Zixuan Chen
089d05e3a0
refactor: expose frontiers type 2023-11-16 22:50:22 +08:00
Zixuan Chen
ed5324b506
chore(release): 0.4.3 2023-11-16 22:26:41 +08:00
Zixuan Chen
f799da9abb
fix: avoid i32 overflow 2023-11-16 22:25:37 +08:00
Zixuan Chen
a484484934
chore(release): 0.4.2 2023-11-16 21:53:04 +08:00
Zixuan Chen
1ff1505933
feat: get sub container directly when getting value (#175) 2023-11-16 21:46:57 +08:00
Zixuan Chen
8957b98236
refactor: emit event after a micro task 2023-11-16 21:04:31 +08:00
Zixuan Chen
40d6de3146
Add map methods for getting keys, values, and entries (#173) 2023-11-16 18:40:51 +08:00
Zixuan Chen
e54d2ac21b
feat(wasm): add event id 2023-11-13 13:06:37 +08:00
leeeon233
c4b753dfd8 chore: add license 2023-11-12 23:23:12 +08:00
Zixuan Chen
2129421b6a
chore(release): 0.4.1 2023-11-12 21:09:42 +08:00
Zixuan Chen
48611c5f15
fix: wasm change peerid should be bigint 2023-11-12 20:36:38 +08:00
Zixuan Chen
d9cd90563f
chore: update test comments 2023-11-11 15:16:28 +08:00
Zixuan Chen
e871a6c438
chore: bump loro-wasm loro-crdt version 2023-11-10 20:41:11 +08:00
Leon zhao
7d2826cfe9
Doc: loro-crdt documents in comments (#165)
* doc: wasm

* doc: add wasm example

* doc: typedoc

* fix: merge

* fix: dep

* fix

---------

Co-authored-by: Zixuan Chen <remch183@outlook.com>
2023-11-10 20:30:54 +08:00
Zixuan Chen
90079b2f1c
test: add more examples 2023-11-10 20:13:01 +08:00
Zixuan Chen
fdd24bd836
feat: add fromCheckout to wasm 2023-11-08 16:22:21 +08:00
Zixuan Chen
a68482a495
test(js): update signature for map set container 2023-11-08 12:12:04 +08:00
Zixuan Chen
83ae5930bc
Fix list get method (#158) 2023-11-07 19:48:16 +08:00
Zixuan Chen
cb8bbefb08
Fix incorrect deletion of emoji in wasm (#154)
This pull request fixes an issue where the emitted utf16 events were wrong when deleting an emoji in wasm. The problem was caused by incorrect calculation of the event range. This PR updates the code to use the correct range and adds a new test case to ensure the issue is fixed.
2023-11-05 16:13:40 +08:00
Zixuan Chen
7ccfd1e91d
feat: expose version and change inspect api to wasm (#156) 2023-11-05 16:06:34 +08:00
Zixuan Chen
5a9baebba0
fix: utf16 query err (#151) 2023-11-04 12:24:05 +08:00
Zixuan Chen
5cac1ed092
Refactor: make changes mergeable (#146)
- Allow changes to be merged when possible. This makes realtime collaboration more efficient with Loro.
- Refactor the code to make modifications of changes in oplog in one place
- Optimize the diff calculation so that it doesn't have to go back to the beginning of the change.

Note: we still keep the invariants that dependency pointers in Loro always point to the last op in a change
2023-11-03 21:40:34 +08:00
Zixuan Chen
7a19b49acb
Add richtext example using Quill (#145)
* feat: richtext example init

* fix: pass richtext event delta consistency check

* chore: debug history
2023-11-03 16:59:27 +08:00
Zixuan Chen
da16b8a99d
refactor: use better repr for container id (#144) 2023-11-02 17:13:08 +08:00
Zixuan Chen
a40b5c6e4a
feat: support richtext in wasm & mark text with arbitrary value (#142)
- Support mark text with custom value [LORO-299] Allow users to mark text with custom value #139
- Expose richtext in wasm
2023-11-02 14:20:34 +08:00
Zixuan Chen
8293347334
Feat: autocommit transaction (#127)
* feat: auto commit

* fix: make recursive single thread event work again
2023-10-30 18:32:36 +08:00
Leon zhao
e01e98411c
feat: movable tree support (#120)
* feat: tree state

* feat: tree value

* feat: tree handler

* fix: tree diff

* test: fuzz tree

* feat: tree snapshot

* fix: tree default value

* fix: test new node

* fix: tree diff

* fix: tree unresolved value

* fix: tree fuzz

* fix: tree fuzz move

* fix: sort by tree id

* fix: tree diff sorted by lamport

* fix: sort roots before tree converted to string

* fix: rebase main

* fix: tree fuzz

* fix: delete undo

* fix: tree to json children sorted

* fix: diff calculate

* fix: diff cycle move

* fix: tree old parent cache

* feat: cache

* fix: local op add tree cache

* fix: don't add same tree move to cache

* fix: need update cache

* feat: new cache

* bench: add checkout bench

* chore: clean

* fix: apply node uncheck

* perf: lamport bound

* fix: calc old parent

* feat: tree wasm

* fix: change tree diff

* fix: tree diff retreat

* fix: tree diff should not apply when add node

* feat: new tree loro value

* chore: typo

* fix: tree deep value

* fix: snapshot tree index -1

* fix: decode tree snapshot use state

* fix: release state lock when emit event

* fix: tree node meta container

* fix: need set map container when covert to local tree op

* fix: tree value add deleted

* fix: more then one op in a change

* fix: tree fuzz deleted equal

* fix: tree calc min lamport

* feat: tree encoding v2

* doc: movable tree

* fix: test tree meta

* test: remove import bytes check

* refactor: diff of text and map

* refactor: del span

* perf: tree state use deleted cache

* fix: some details

* fix: loro js tree create

* feat: add un exist tree node

* bench:  tree depth

* fix: check out should emit event

* refactor: event

* fix: fuzz err

* fix: pass all tests

* fix: fuzz err

* fix: list child cache err

* chore: rm debug code

* fix: encode enhanced err

* fix: encode enchanced

* fix: fix several richtext issue

* fix: richtext anchor err

* chore: rm debug code

* fix: richtext fuzz err

* feat: speedup text snapshot decode

* perf: optimize snapshot encoding

* perf: speed up decode & insert

* fix: fugue span merge err

* perf: speedup delete & id cursor map

* fix: fugue merge err

* chore: update utils

* fix: fix merge

* fix: return err apply op

* fix: fix merge

* fix: get map container as tree meta
2023-10-30 11:13:52 +08:00
Zixuan Chen
d942e3d7a2
Feat: Peritext-like rich text support (#123)
* feat: richtext wip

* feat: add insert to style range map wip

* feat: richtext state

* fix: fix style state inserting and style map

* fix: tiny vec merge err

* fix: comment err

* refactor: use new generic-btree & refine impl

* feat: fugue tracker

* feat: tracker

* feat: tracker

* fix: fix a few err in impl

* feat: init richtext content state

* feat: refactor arena

* feat: extract anchor_type info out of style flag

* refactor: state apply op more efficiently
we can now reuse the repr in state and op

* fix: new clippy errors

* refactor: use state chunk as delta item

* refactor: use two op to insert style start and style end

* feat: diff calc

* feat: handler

* fix: tracker checkout err

* fix: pass basic richtext handler tests

* fix: pass handler basic marking tests

* fix: pass all peritext criteria

* feat: snapshot encoding for richtext init

* refactor: replace Text with Richtext

* refacotr: rm text code

* fix: richtext checkout err

* refactor: diff of text and map

* refactor: del span

* refactor: event

* fix: fuzz err

* fix: pass all tests

* fix: fuzz err

* fix: list child cache err

* chore: rm debug code

* fix: encode enhanced err

* fix: encode enchanced

* fix: fix several richtext issue

* fix: richtext anchor err

* chore: rm debug code

* fix: richtext fuzz err

* feat: speedup text snapshot decode

* perf: optimize snapshot encoding

* perf: speed up decode & insert

* fix: fugue span merge err

* perf: speedup delete & id cursor map

* fix: fugue merge err

* chore: update utils

* perf: speedup text insert / del

* fix: cursor cache

* perf: reduce conversion by introducing InsertText

* perf: speed up by refined cursor cache

* chore: update gbtree dep

* refactor(wasm): use quill delta format

* chore: fix warnings
2023-10-29 14:02:13 +08:00
leeeon233
331dc6c994 feat: LoroValue Binary 2023-09-12 15:57:06 +08:00
Zixuan Chen
c105ff2220
Feat: checkout to target version & use unicode index by default (#98)
* feat: checkout to frontiers

* feat: record timestamp

* fix: use unicode len by default for text
now "你好" has length of 2 instead of 6

* chore: rm dbg!
2023-08-04 10:45:23 +08:00
Zixuan Chen
6860132ada refactor: call events subs without await now 2023-07-30 17:08:49 +08:00
Zixuan Chen
88003bdffe fix: get deep value & throw mismatched context err 2023-07-30 16:30:41 +08:00
Zixuan Chen
c461edd828 refactor: remove utf16 meta in text event
we will use utf16 index by default when feature=wasm
2023-07-29 22:24:09 +08:00
Zixuan Chen
15be521777 feat: event & wasm 2023-07-29 02:03:51 +08:00
Zixuan Chen
794ed42ea4 chore: bump version 2023-05-11 12:19:47 +08:00
Zixuan Chen
bc09a0489f
feat: add typed versions of getMap and getList to Loro class (#96)
* feat: add typed versions of getMap and getList to Loro class

This commit adds `getTypedMap` and `getTypedList` methods to the `Loro` class, which allow for accessing maps and lists with type information. It also adds corresponding `getTyped`, `insertTyped`, and `setTyped` methods to `LoroMap` and `LoroList`. This makes it easier and safer to work with Loro's data structures.

* chore: bump version

* chore: alpha 1

* feat: add size and length to list and map

* chore: update deno test script
2023-05-11 11:59:48 +08:00
Zixuan Chen
023b2ab87d release: loro-crdt 0.2.7 2023-04-07 16:40:01 +08:00
Zixuan Chen
c61f238039 release: 0.2.6 loro-crdt 2023-04-07 16:36:48 +08:00
Zixuan Chen
598f6dbc33 release: loro-crdt v0.2.5 2023-04-07 14:29:18 +08:00
Zixuan Chen
0a31b67dd4
Feat: expose frontier & make it comparable (#95)
* refactor: make frontiers a new type

* feat: compare frontiers
2023-04-05 20:31:58 +08:00
Leon zhao
e51d6f8760
Fix: use Transaction to decode/import (#92) 2023-04-04 21:44:41 +08:00
Zixuan Chen
3e64116621
fix: make text event in wasm use utf16 as index and len (#88)
* feat: utf16 event for wasm (draft, buggy)

* fix: work around the issue of unknown text content

* fix: utf16 err

* fix: compose utf16 meta

* docs: add comments
2023-04-03 20:03:07 +08:00
Zixuan Chen
82b5f8dc90
Perf: speed up utf16 and wasm (#90)
* perf: remove unused transact field

* perf: micro optimization

* bench: fix bench

* bench: add utf16 bench

* chore: refine diagnose

* perf: speedup utf16 lookup

* perf: use better utf16 len counter

* refactor: use js to cast Loro/Transaction

* refactor: map and list use __loro and __txn

* test: configure ci vitest

* chore: ci
2023-04-03 09:29:25 +08:00
Zixuan Chen
63cd719393 chore: bump loro-crdt version 2023-03-28 23:23:19 +08:00
Zixuan Chen
abafec9e18 chore: bump versions 2023-03-28 01:05:17 +08:00
Zixuan Chen
6df69bd2be feat: add subscribe to containers in wasm 2023-03-25 20:11:45 +08:00
Zixuan Chen
39ece045a8 feat: add return type for map and list 2023-03-25 20:11:45 +08:00
Zixuan Chen
0a421d3931 fix: add event diff test & fix related bugs 2023-03-25 20:11:45 +08:00
Zixuan Chen
49f664dd8f feat: convert event to js & add vitest 2023-03-25 20:11:45 +08:00
Zixuan Chen
606685d42b chore: bump version 2023-03-24 11:50:10 +08:00
Zixuan Chen
aadde5af9e fix: loro-crdt type
Co-authored-by: Leonzhao <leeeon233@gmail.com>
2023-03-24 11:44:32 +08:00
Zixuan Chen
74a7aa6c1a fix: transaction 2023-03-24 11:20:59 +08:00
Zixuan Chen
2f74b13e70 feat: extra pkg loro-crdt to wrap loro-wasm 2023-03-24 10:08:11 +08:00