Commit graph

866 commits

Author SHA1 Message Date
Orion Henry
ac90f8f028 Merge remote-tracking branch 'origin/freeze' into f2 2022-10-17 16:21:35 -05:00
Orion Henry
c602e9e7ed update build to match directory restructuring 2022-10-17 16:20:25 -05:00
Alex Good
1c6da6f9a3
Add JS worker config to Vite app example
Vite apps which use SharedWorker of WebWorker require additional
configuration to get WebAssembly imports to work effectively, add these
to the example.
2022-10-17 01:09:13 +01:00
Alex Good
24dcf8270a
Add typedoc comments to the entire public JS API 2022-10-17 00:41:06 +01:00
Alex Good
e189ec9ca8
Add some READMEs to the javascript directory 2022-10-16 20:01:49 +01:00
Alex Good
96f15c6e00
Update main README to reflect new repo layout 2022-10-16 20:01:45 +01:00
Alex Good
8e131922e7
Move wrappers/javascript -> javascript
Continuing our theme of treating all languages equally, move
wrappers/javascript to javascrpit. Automerge libraries for new languages
should be built at this top level if possible.
2022-10-16 19:55:54 +01:00
Alex Good
dd3c6d1303
Move rust workspace into ./rust
After some discussion with PVH I realise that the repo structure in the
last reorg was very rust-centric. In an attempt to put each language on
a level footing move the rust code and project files into ./rust
2022-10-16 19:55:51 +01:00
Orion Henry
5ce3a556a9 weak_refs 2022-10-16 19:55:25 +01:00
Orion Henry
dd5edafa9d make freeze work recursively 2022-10-15 21:21:18 -05:00
Alex Good
cd2997e63f
@automerge/automerge@2.0.0-alpha.5 and @automerge/automerge-wasm@0.1.10 2022-10-13 23:13:09 +01:00
Orion Henry
f0f036eb89
add loadIncremental to js 2022-10-13 23:03:01 +01:00
Alex Good
ee0c3ef3ac javascript: Make getObjectId tolerate non object arguments
Fixes #433. `getObjectId` was previously throwing an error if passed
something which was not an object. In the process of fixing this I
simplified the logic of `getObjectId` by modifying automerge-wasm to not
set the OBJECT_ID hidden property on objects which are not maps, lists,
or text - it was previously setting this property on anything which was
a JS object, including `Date` and `Uint8Array`.
2022-10-13 21:37:37 +01:00
Orion Henry
e6d1828c12
Merge pull request #440 from automerge/repo-reorg
Repo reorg
2022-10-12 10:07:02 -07:00
Alex Good
4c17fd9c00
Update README
We're making this project the primary implementation of automerge.
Update the README to provide more context and signpost other resources.
2022-10-12 16:25:43 +01:00
Alex Good
660678d038
remove unneeded files 2022-10-12 16:25:43 +01:00
Alex Good
a7a4bd42f1
Move automerge-js -> wrappers/javascript
Whilst we only have one wrapper library, we anticipate more.
Furthermore, the naming of the `wrappers` directory makes it clear what
the role of the JS codebase is.
2022-10-12 16:25:43 +01:00
Alex Good
352a0127c7
Move all rust code into crates/*
For larger rust projects it's common to put all rust code in a directory
called `crates`. This helps in general by reducing the number of
directories in the top level but it's particularly helpful for us
because some directories _do not_ contain Rust code. In particular
`automerge-js`. Move rust code into `/crates` to make the repo easier
to navigate.
2022-10-12 16:25:38 +01:00
Alex Good
ed0da24020
Track whether a transaction is observed in types
With the `OpObserver` moving to the transaction rather than being passed
in to the `Transaction::commit` method we have needed to add a way to
get the observer back out of the transaction (via
`Transaction::observer` and `AutoCommit::observer`). This `Observer`
type is then used to handle patch generation logic. However, there are
cases where we might not want an `OpObserver` and in these cases we can
execute various things fast - so we need to have something like an
`Option<OpObserver>`. In order to track the presence or otherwise of the
observer at the type level introduce
`automerge::transaction::observation`, which is a type level `Option`.
This allows us to efficiently choose the right code paths whilst
maintaining correct types for `Transaction::observer` and
`AutoCommit::observer`
2022-10-12 16:11:23 +01:00
Orion Henry
3989cac405
Merge pull request #439 from automerge/type-patchcallback
Add TypeScript type for PatchCallback
2022-10-10 14:25:43 -07:00
Alex Good
2d072d81fb
Add TypeScript type for PatchCallback 2022-10-10 21:19:39 +01:00
Alex Good
430d842343
Update vite.config.js in Vite Example README 2022-10-10 14:14:38 +01:00
Alex Good
dff0fc2b21
Remove automerge-wasm devDependency
This dependency was added in a PR which is no longer relevant as we've
switched to depending directly on `@automerge/automerge-wasm` and
testing by running a local NPM registry.
2022-10-10 13:05:10 +01:00
Orion Henry
9e1fe65a64
Merge pull request #429 from automerge/actually-run-js-tests
Use the local automerge-wasm in automerge-js tests
2022-10-06 15:41:07 -07:00
Orion Henry
3d5fe83e2b
Merge branch 'main' into actually-run-js-tests 2022-10-06 15:41:01 -07:00
Alex Good
ba328992ff
bump @automerge/automerge-wasm and @automerge/automerge versions 2022-10-06 22:53:21 +01:00
Orion Henry
23a07699e2
typescript fixes 2022-10-06 22:42:33 +01:00
Orion Henry
238d05a0e3
move automerge-js onto the applyPatches model 2022-10-06 22:42:31 +01:00
Orion Henry
7a6dfcc289
The patch interface needs an accurate path per patch op
For the path to be accurate it needs to be calculated at the moment of op insert
not at commit.  This is because the path may contain list indexes in parent
objects that could change by inserts and deletes later in the transaction.

The primary change was adding op_observer to the transaction object and
removing it from commit options.  The beginnings of a wasm level
`applyPatch` system is laid out here.
2022-10-06 22:41:37 +01:00
Alex Good
92145e6131
@automerge/automerge-wasm 0.1.8 2022-10-05 00:55:10 +01:00
Alex Good
2012f5c6e4
Fix some typescript bugs, automerge-js 2.0.0-alpha.3 2022-10-05 00:52:36 +01:00
Alex Good
fb4d1f4361
Ship generated typescript types correctly
Generated typescript types were being shipped in the `dist/cjs` and `dist/mjs`
directories but are referenced at the top level in package.json. Add a
step to generate `*.d.ts` files in the top level `dist/*.d.ts`.
2022-10-04 22:54:19 +01:00
Alex Good
74af537800
Rename automerge and automerge-wasm packages
In an attempt to make our package naming more understandable we move all
our packages to a single NPM scope. `automerge` ->
`@automerge/automerge` and `automerge-wasm` ->
@automerge/automerge-wasm`
2022-10-04 22:05:56 +01:00
Alex Good
29f2c9945e query::Prop: don't scan past end of OpTree
The logic in `query::Prop` works by first doing a binary search in the
OpTree for the node where the key we are looking for starts, and then
proceeding from this point forwards skipping over nodes which contain
only invisible ops. This logic was incorrect if the start index returned
by the binary search was in the last child of the optree and the last
child only contains invisible ops. In this case the index returned by
the query would be greater than the length of the optree.

Clamp the index returned by the query to the total length of the opset.
2022-10-04 17:25:56 +01:00
Alex Good
d6a8d41e0a Update JS README 2022-10-04 17:23:37 +01:00
Alex Good
b6c375efb9 Fix a few small typescript complaints 2022-10-04 17:23:37 +01:00
Alex Good
16f2272b5b Generate index.d.ts from source
The JS package is now written in typescript so we don't need to manually
maintain an index.d.ts file. Generate the index.d.ts file from source
and ship it with the JS package.
2022-10-04 17:23:37 +01:00
Alex Good
da51492327 build both nodejs and bundler packages in yarn build 2022-10-04 17:23:37 +01:00
Alex Good
577bda3e7f update wasm-bindgen 2022-10-04 17:23:37 +01:00
Alex Good
20dc0fb54e Set optimization levels to 'Z' for release profile
This reduces the size of the WASM bundle which is generated to around
800kb. Unfortunately wasm-pack doesn't allow us to use arbitrary
profiles when building and the optimization level has to be set at the
workspace root - consequently this flag is set for all packages in the
workspace. This shouldn't be an issue really as all our dependents in
the Rust world will be setting their own optimization flags anyway.
2022-10-04 17:23:37 +01:00
Alex Good
4f03cd2a37 Add an e2e testing tool for the JS packaging
JS packaging is complicated and testing it manually is irritating. Add a
tool in `automerge-js/e2e` which stands up a local NPM registry and
publishes the various packages to that registry for use in automated and
manual tests. Update the test script in `scripts/ci/js_tests` to run the
tests using this tool
2022-10-04 17:23:37 +01:00
Alex Good
7825da3ab9 Add examples of using automerge with bundlers 2022-10-04 17:23:37 +01:00
Alex Good
8557ce0b69 Rename automerge-js to automerge
Now that automerge-js is ready to go we rename it to `automerge-js` and
set the version to `2.0.0-alpha.1`
2022-10-04 17:23:37 +01:00
Alex Good
a9e23308ce Remove async automerge-wasm wrapper
By moving to wasm-bindgens `bundler` target rather than using the `web`
target we remove the need for an async initialization step on the
automerge-wasm package. This means that the automerge-js package can now
depend directly on automerge-wasm and perform initialization itself,
thus making automerge-js a drop in replacement for the `automerge` JS
package (hopefully).

We bump the versions of automerge-wasm
2022-10-04 17:23:37 +01:00
Alex Good
837c07b23a
Correctly encode compressed changes in sync messages
Sync messages encode changes as length prefixed byte arrays. We were
calculating the length using the uncompressed bytes of a change but
encoding the bytes of the change using the (possibly) compressed bytes.
This meant that if a change was large enough to compress then it  would
fail to decode. Switch to using uncompressed bytes in sync messages.
2022-10-02 18:59:41 +01:00
Alex Good
3d59e61cd6
Allow empty changes when loading document format
The logic for loading compressed document chunks has a check that the
`max_op` of a change is valid. This check was overly strict in that it
checked that the max op was strictly larger than the max op of a
previous strange - this rejects valid documents which contain changes
with no ops in them, in which case the max op can be equal to the max op
of the previous change. Loosen the logic to allow empty changes.
2022-09-30 19:00:48 +01:00
Alex Good
e57548f6e2
Fix broken encode/decode change
Previous ceremonies to appease clippy resulted in the
encodeChange/decodeChange wasm functions being slightly broken. Here we
fix them.
2022-09-29 15:49:31 -05:00
Alex Good
c7e370a1df
Appease clippy 2022-09-28 17:18:37 -05:00
Alex Good
427002caf3 Correctly load documents with deleted objects
The logic for reconstructing changes from the compressed document format
records operations which set a key in an object so that it can later
reconstruct delete operations from the successor list of the document
format operations. The logic to do this was only recording set
operations and not `make*` operations. This meant that delete operations
targeting `make*` operations could not be loaded correctly.

Correctly record `make*` operations for later use in constructing delete
operations.
2022-09-12 12:38:57 +01:00
Alex Good
fc9cb17b34
Use the local automerge-wasm in automerge-js tests
Somehow the `devDependencies` for `automerge-js` dependended on the
released `automerge-wasm` package, rather than the local version, which
means that the JS tests are not actually testing the current
implementation. Depend on the local `automerge-wasm` package to fix
this.
2022-09-08 16:27:30 +01:00