Skip to content

Commit 51637ef

Browse files
authored
Merge pull request #40 from mixedrays/develop
Release
2 parents a3ce865 + f59eecd commit 51637ef

269 files changed

Lines changed: 17284 additions & 2669 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
"@homeostate/crdt-automerge": patch
3+
---
4+
5+
Implement the `CrdtBackend` whose `read` returns a `JsonObject` and whose `write` takes a
6+
`JsonObjectInput`. `read()` throws a `TypeError` naming what the synced key holds when a peer
7+
stored something other than a map there, such as a string, a list or `null`, instead of
8+
returning it, or `{}` for `null`. The sync engine reports it as before, and `write` still
9+
replaces the value with a map. Use it with the `@homeostate/core` release that narrows
10+
`CrdtBackend.read` and `write`.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
"@homeostate/crdt-automerge": patch
3+
---
4+
5+
Report and hear changes made while an update is applied. `createAutomergePersistable` skipped
6+
every change to the handle while `apply` ran, so a change a handle listener made in response,
7+
such as the sync engine writing what a store derived from the update, was neither stored nor
8+
relayed, and the peers that missed it could not apply any later change of that document.
9+
`apply` now skips only the update it applies. `createAutomergeBackend` ignored every change
10+
while its own write notified, so a peer's update merged at that moment, as a synchronous relay
11+
does, never reached the store; it now ignores only its own write.

‎.changeset/automerge-doc-source.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@homeostate/crdt-automerge": minor
3+
---
4+
5+
`createAutomergeBackend` accepts any object with `doc`, `change` and `subscribe`, exported as
6+
`AutomergeDocSource`, so a document holder of your own no longer needs an `update` the backend
7+
never calls.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
"@homeostate/crdt-automerge": minor
3+
---
4+
5+
Sync a document kept by automerge-repo. `createAutomergeBackend` now takes a `DocHandle` as
6+
well as an `AutomergeHandle`, so a `Repo`'s storage and network adapters store and sync what the
7+
engine writes:
8+
9+
```ts
10+
createAutomergeBackend(await repo.find(url), "shared");
11+
```
12+
13+
The engine picks up every change that did not come through its own write: changes loaded from
14+
storage, received from peers, or made through `docHandle.change`. Either handle may now hold any
15+
document type, such as the `unknown` of an untyped `repo.find` or an interface.

‎.changeset/automerge-revision.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@homeostate/crdt-automerge": minor
3+
---
4+
5+
Implement `CrdtBackend.revision` from the document's heads. The sync engine then applies a remote
6+
change another listener heard of first before writing a local change, instead of the write
7+
bringing back what the peer had deleted.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
"@homeostate/crdt-automerge": patch
3+
---
4+
5+
Throw from `createAutomergePersistable`'s `apply` for bytes that are not Automerge data. Once a
6+
document held changes, `A.loadIncremental` skipped such bytes silently, so `createPersistence`
7+
took a log holding damaged bytes or another CRDT library's update for one it had restored in
8+
full, and compacted them away. A repeated update, or one waiting for an earlier change, still
9+
applies without an error.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
"@homeostate/core": minor
3+
---
4+
5+
Breaking: `Change` is a discriminated union of objects instead of a `[type, key, value]` tuple,
6+
and `ChangeType` is a const object instead of an `enum`. A script holds one kind of step:
7+
`RecordChange` for a record, keyed by property name, and `ListChange` or `TextChange` for an
8+
array or a string, keyed by position. `getChanges` returns the script of the kind of the values
9+
it diffs, or an `EditScript` for values typed only as `Diffable`, and `applyStringChanges` takes
10+
a `TextChange[]`. Narrowing a step by `type`, and a pending step by `kind`, replaces the casts.
11+
12+
Adjacent array items or characters deleted together are now one `delete` step with a `count`,
13+
which `applyChanges` passes to `splice` or `editText` as one call. Clearing a 5000-item list or a
14+
5000-character text through the Yjs backend takes one `delete` instead of 5000, and about 1 ms
15+
instead of 100 to 250 ms.
16+
17+
To migrate code that reads or builds changes:
18+
19+
- Destructure properties instead of the tuple: `const { type, key } = change`. An insert or
20+
update carries `value`; a pending step carries `kind` (`"record"`, `"list"` or `"text"`) and
21+
its nested `changes`, which used to be its third entry.
22+
- Apply an array or string delete's `count`, treating an absent one as `1`. A string delete's
23+
length used to be its third entry. `getChanges` sets it on every array and string delete.
24+
- `ChangeType.INSERT` and the other members keep their values, and `ChangeType` is still the
25+
type of the four strings. Code that relied on the `enum` type, rather than its values, now
26+
takes the string literals.
27+
- Annotate scripts as `RecordChange[]`, `ListChange[]`, `TextChange[]` or `EditScript` instead of
28+
`Change[]`, which is a single step of any kind.
29+
30+
`ApplyOps` is unchanged, so backends and stores that apply changes through `applyChanges` need
31+
no change.

‎.changeset/crdt-backend-parts.md‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
"@homeostate/core": minor
3+
---
4+
5+
Export `createCrdtBackend(build, options?)`, which builds a `CrdtBackend` from the parts that
6+
differ by CRDT library, described by `CrdtBackendParts`: `read`, `transact`, which runs one edit
7+
tagged as the backend's own with the library's `ApplyOps`, `watch`, which says whether each
8+
change was the backend's own, and optionally `revision`. `build` receives the text policy from
9+
`CrdtBackendOptions.text`, which defaults to none. The backend it returns diffs each write
10+
against `previous`, or against the document when there is none, or against `{}` when `transact`
11+
had to create the synced map, with `applyChanges` and `json: true`, and leaves its own writes out
12+
of `subscribe`. A backend for another CRDT library no longer has to repeat these steps.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
"@homeostate/crdt-yjs": patch
3+
"@homeostate/crdt-loro": patch
4+
"@homeostate/crdt-automerge": patch
5+
---
6+
7+
Build the backend with `createCrdtBackend` from `@homeostate/core`, so the default text policy,
8+
what a write diffs against and leaving its own writes out of `subscribe` are written once, in
9+
core. Options, extras such as the Yjs backend's `map` and `origin`, and behaviour are unchanged.
10+
Use it with the `@homeostate/core` release that adds `createCrdtBackend`.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
"@homeostate/crdt-yjs": patch
3+
"@homeostate/crdt-loro": patch
4+
---
5+
6+
Leave copying objects that a peer's `__proto__` entry gave a prototype to the sync engine, which
7+
now does it for every backend. `read()` may return such an object as the document holds it; the
8+
store still never receives one. The Yjs backend still leaves `__proto__` entries of a `Y.Map`
9+
out of what it reads. Use it with the `@homeostate/core` release whose engine copies such objects.

0 commit comments

Comments
 (0)