From bcbac032289d8ab0db426f5af8a83a126469393c Mon Sep 17 00:00:00 2001 From: Andras Schmelczer Date: Sun, 15 Jun 2025 11:30:07 +0100 Subject: [PATCH] Merge crates --- Cargo.lock | 42 +------------ Cargo.toml | 43 +++++++++---- reconcile/Cargo.toml | 23 ------- {reconcile/src => src}/diffs.rs | 0 {reconcile/src => src}/diffs/myers.rs | 0 {reconcile/src => src}/diffs/raw_operation.rs | 0 ...le__diffs__myers__tests__complex_diff.snap | 0 ...ile__diffs__myers__tests__delete_only.snap | 0 ...iffs__myers__tests__identical_content.snap | 0 ...ile__diffs__myers__tests__insert_only.snap | 0 ...iffs__myers__tests__prefix_and_suffix.snap | 0 {reconcile/src => src}/lib.rs | 3 + .../src => src}/operation_transformation.rs | 0 .../operation_transformation/cursor.rs | 0 .../operation_transformation/edited_text.rs | 0 .../operation_transformation/merge_context.rs | 0 .../operation_transformation/operation.rs | 0 .../ordered_operation.rs | 0 ...ted_text__tests__calculate_operations.snap | 0 ...ts__calculate_operations_with_no_diff.snap | 0 ...ted_text__tests__calculate_operations.snap | 0 ...sequence__tests__calculate_operations.snap | 0 .../operation_transformation/utils.rs | 0 .../utils/cook_operations.rs | 0 .../utils/elongate_operations.rs | 0 {reconcile/src => src}/tokenizer.rs | 0 ...rd_tokenizer__tests__with_snapshots-2.snap | 0 ...rd_tokenizer__tests__with_snapshots-3.snap | 0 ...rd_tokenizer__tests__with_snapshots-4.snap | 0 ...rd_tokenizer__tests__with_snapshots-5.snap | 0 ...word_tokenizer__tests__with_snapshots.snap | 0 {reconcile/src => src}/tokenizer/token.rs | 0 .../src => src}/tokenizer/word_tokenizer.rs | 0 {reconcile/src => src}/utils.rs | 0 .../src => src}/utils/common_prefix_len.rs | 0 .../src => src}/utils/common_suffix_len.rs | 0 .../find_longest_prefix_contained_within.rs | 0 {reconcile/src => src}/utils/side.rs | 0 .../src => src}/utils/string_builder.rs | 0 src/wasm.rs | 2 + {sync_lib/src => src/wasm}/cursor.rs | 38 +++++------ {sync_lib/src => src/wasm}/lib.rs | 63 +++---------------- sync_lib/Cargo.toml | 32 ---------- sync_lib/src/errors.rs | 29 --------- .../snapshots/web__base64_to_bytes_error.snap | 10 --- .../tests => tests}/example_document.rs | 0 {reconcile/tests => tests}/examples/README.md | 0 .../tests => tests}/examples/deletes.yml | 0 .../examples/deletes_and_inserts.yml | 0 .../examples/idempotent_inserts.yml | 0 .../tests => tests}/examples/multiline.yml | 0 .../tests => tests}/examples/replacing.yml | 0 {reconcile/tests => tests}/examples/utf-8.yml | 0 .../tests => tests}/examples/various.yml | 0 {reconcile/tests => tests}/resources/blns.txt | 0 .../tests => tests}/resources/kun_lu.txt | 0 .../resources/pride_and_prejudice.txt | 0 .../resources/room_with_a_view.txt | 0 {reconcile/tests => tests}/test.rs | 0 {sync_lib/tests => tests}/web.rs | 36 +++-------- 60 files changed, 73 insertions(+), 248 deletions(-) delete mode 100644 reconcile/Cargo.toml rename {reconcile/src => src}/diffs.rs (100%) rename {reconcile/src => src}/diffs/myers.rs (100%) rename {reconcile/src => src}/diffs/raw_operation.rs (100%) rename {reconcile/src => src}/diffs/snapshots/reconcile__diffs__myers__tests__complex_diff.snap (100%) rename {reconcile/src => src}/diffs/snapshots/reconcile__diffs__myers__tests__delete_only.snap (100%) rename {reconcile/src => src}/diffs/snapshots/reconcile__diffs__myers__tests__identical_content.snap (100%) rename {reconcile/src => src}/diffs/snapshots/reconcile__diffs__myers__tests__insert_only.snap (100%) rename {reconcile/src => src}/diffs/snapshots/reconcile__diffs__myers__tests__prefix_and_suffix.snap (100%) rename {reconcile/src => src}/lib.rs (88%) rename {reconcile/src => src}/operation_transformation.rs (100%) rename {reconcile/src => src}/operation_transformation/cursor.rs (100%) rename {reconcile/src => src}/operation_transformation/edited_text.rs (100%) rename {reconcile/src => src}/operation_transformation/merge_context.rs (100%) rename {reconcile/src => src}/operation_transformation/operation.rs (100%) rename {reconcile/src => src}/operation_transformation/ordered_operation.rs (100%) rename {reconcile/src => src}/operation_transformation/snapshots/reconcile__operation_transformation__edited_text__tests__calculate_operations.snap (100%) rename {reconcile/src => src}/operation_transformation/snapshots/reconcile__operation_transformation__edited_text__tests__calculate_operations_with_no_diff.snap (100%) rename {reconcile/src => src}/operation_transformation/snapshots/reconcile__operations__edited_text__tests__calculate_operations.snap (100%) rename {reconcile/src => src}/operation_transformation/snapshots/reconcile__operations__operation_sequence__tests__calculate_operations.snap (100%) rename {reconcile/src => src}/operation_transformation/utils.rs (100%) rename {reconcile/src => src}/operation_transformation/utils/cook_operations.rs (100%) rename {reconcile/src => src}/operation_transformation/utils/elongate_operations.rs (100%) rename {reconcile/src => src}/tokenizer.rs (100%) rename {reconcile/src => src}/tokenizer/snapshots/reconcile__tokenizer__word_tokenizer__tests__with_snapshots-2.snap (100%) rename {reconcile/src => src}/tokenizer/snapshots/reconcile__tokenizer__word_tokenizer__tests__with_snapshots-3.snap (100%) rename {reconcile/src => src}/tokenizer/snapshots/reconcile__tokenizer__word_tokenizer__tests__with_snapshots-4.snap (100%) rename {reconcile/src => src}/tokenizer/snapshots/reconcile__tokenizer__word_tokenizer__tests__with_snapshots-5.snap (100%) rename {reconcile/src => src}/tokenizer/snapshots/reconcile__tokenizer__word_tokenizer__tests__with_snapshots.snap (100%) rename {reconcile/src => src}/tokenizer/token.rs (100%) rename {reconcile/src => src}/tokenizer/word_tokenizer.rs (100%) rename {reconcile/src => src}/utils.rs (100%) rename {reconcile/src => src}/utils/common_prefix_len.rs (100%) rename {reconcile/src => src}/utils/common_suffix_len.rs (100%) rename {reconcile/src => src}/utils/find_longest_prefix_contained_within.rs (100%) rename {reconcile/src => src}/utils/side.rs (100%) rename {reconcile/src => src}/utils/string_builder.rs (100%) create mode 100644 src/wasm.rs rename {sync_lib/src => src/wasm}/cursor.rs (60%) rename {sync_lib/src => src/wasm}/lib.rs (68%) delete mode 100644 sync_lib/Cargo.toml delete mode 100644 sync_lib/src/errors.rs delete mode 100644 sync_lib/tests/snapshots/web__base64_to_bytes_error.snap rename {reconcile/tests => tests}/example_document.rs (100%) rename {reconcile/tests => tests}/examples/README.md (100%) rename {reconcile/tests => tests}/examples/deletes.yml (100%) rename {reconcile/tests => tests}/examples/deletes_and_inserts.yml (100%) rename {reconcile/tests => tests}/examples/idempotent_inserts.yml (100%) rename {reconcile/tests => tests}/examples/multiline.yml (100%) rename {reconcile/tests => tests}/examples/replacing.yml (100%) rename {reconcile/tests => tests}/examples/utf-8.yml (100%) rename {reconcile/tests => tests}/examples/various.yml (100%) rename {reconcile/tests => tests}/resources/blns.txt (100%) rename {reconcile/tests => tests}/resources/kun_lu.txt (100%) rename {reconcile/tests => tests}/resources/pride_and_prejudice.txt (100%) rename {reconcile/tests => tests}/resources/room_with_a_view.txt (100%) rename {reconcile/tests => tests}/test.rs (100%) rename {sync_lib/tests => tests}/web.rs (67%) diff --git a/Cargo.lock b/Cargo.lock index f7edcc9..19871fb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,12 +2,6 @@ # It is not intended for manual editing. version = 4 -[[package]] -name = "base64" -version = "0.22.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" - [[package]] name = "bumpalo" version = "3.16.0" @@ -206,11 +200,14 @@ dependencies = [ name = "reconcile" version = "0.4.0" dependencies = [ + "console_error_panic_hook", "insta", "pretty_assertions", "serde", "serde_yaml", "test-case", + "wasm-bindgen", + "wasm-bindgen-test", ] [[package]] @@ -290,19 +287,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "sync_lib" -version = "0.4.0" -dependencies = [ - "base64", - "console_error_panic_hook", - "insta", - "reconcile", - "thiserror", - "wasm-bindgen", - "wasm-bindgen-test", -] - [[package]] name = "test-case" version = "3.3.1" @@ -336,26 +320,6 @@ dependencies = [ "test-case-core", ] -[[package]] -name = "thiserror" -version = "2.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "567b8a2dae586314f7be2a752ec7474332959c6460e02bde30d702a66d488708" -dependencies = [ - "thiserror-impl", -] - -[[package]] -name = "thiserror-impl" -version = "2.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f7cf42b4507d8ea322120659672cf1b9dbb93f8f2d4ecfd6e51350ff5b17a1d" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "unicode-ident" version = "1.0.14" diff --git a/Cargo.toml b/Cargo.toml index cdbb0f9..2f666ad 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,21 +1,38 @@ -[workspace] -resolver = "2" -members = [ - "reconcile", - "sync_lib" -] - -[workspace.package] -rust-version = "1.83" +[package] +name = "reconcile" +rust-version = "1.85" authors = ["Andras Schmelczer "] edition = "2024" license = "MIT" -repository = "https://github.com/schmelczer/vault-link" +repository = "https://github.com/schmelczer/reconcile" version = "0.4.0" -[workspace.dependencies] -serde = { version = "1.0.219", default-features = false, features = ["derive"] } -thiserror = { version = "2.0.12", default-features = false } +[lib] +crate-type = ["cdylib", "rlib"] + +[dependencies] +serde = { version = "1.0.219", optional = true, features = ["derive"] } + +wasm-bindgen = { version = "0.2.99", optional = true } + +# The `console_error_panic_hook` crate provides better debugging of panics by +# logging them with `console.error`. This is great for development, but requires +# all the `std::fmt` and `std::panicking` infrastructure, so isn't great for +# code size when deploying. +console_error_panic_hook = { version = "0.1.7", optional = true } + +[features] +default = ["serde", "wasm"] +serde = [ "dep:serde" ] +wasm = [ "dep:wasm-bindgen", "dep:console_error_panic_hook" ] + +[dev-dependencies] +insta = "1.42.2" +pretty_assertions = "1.4.1" +serde = { version = "1.0.219", features = ["derive"] } +serde_yaml ="0.9.34" +test-case = "3.3.1" +wasm-bindgen-test = "0.3.49" [profile.release] codegen-units = 1 diff --git a/reconcile/Cargo.toml b/reconcile/Cargo.toml deleted file mode 100644 index 61e7edf..0000000 --- a/reconcile/Cargo.toml +++ /dev/null @@ -1,23 +0,0 @@ -[package] -name = "reconcile" -version.workspace = true -edition.workspace = true -authors.workspace = true -license.workspace = true -repository.workspace = true - -[dependencies] -serde = { version = "1.0.219", optional = true, features = ["derive"] } - -[features] -serde = [ "dep:serde" ] - -[dev-dependencies] -insta = "1.42.2" -pretty_assertions = "1.4.1" -serde = { version = "1.0.219", features = ["derive"] } -serde_yaml ="0.9.34" -test-case = "3.3.1" - -[lints] -workspace = true diff --git a/reconcile/src/diffs.rs b/src/diffs.rs similarity index 100% rename from reconcile/src/diffs.rs rename to src/diffs.rs diff --git a/reconcile/src/diffs/myers.rs b/src/diffs/myers.rs similarity index 100% rename from reconcile/src/diffs/myers.rs rename to src/diffs/myers.rs diff --git a/reconcile/src/diffs/raw_operation.rs b/src/diffs/raw_operation.rs similarity index 100% rename from reconcile/src/diffs/raw_operation.rs rename to src/diffs/raw_operation.rs diff --git a/reconcile/src/diffs/snapshots/reconcile__diffs__myers__tests__complex_diff.snap b/src/diffs/snapshots/reconcile__diffs__myers__tests__complex_diff.snap similarity index 100% rename from reconcile/src/diffs/snapshots/reconcile__diffs__myers__tests__complex_diff.snap rename to src/diffs/snapshots/reconcile__diffs__myers__tests__complex_diff.snap diff --git a/reconcile/src/diffs/snapshots/reconcile__diffs__myers__tests__delete_only.snap b/src/diffs/snapshots/reconcile__diffs__myers__tests__delete_only.snap similarity index 100% rename from reconcile/src/diffs/snapshots/reconcile__diffs__myers__tests__delete_only.snap rename to src/diffs/snapshots/reconcile__diffs__myers__tests__delete_only.snap diff --git a/reconcile/src/diffs/snapshots/reconcile__diffs__myers__tests__identical_content.snap b/src/diffs/snapshots/reconcile__diffs__myers__tests__identical_content.snap similarity index 100% rename from reconcile/src/diffs/snapshots/reconcile__diffs__myers__tests__identical_content.snap rename to src/diffs/snapshots/reconcile__diffs__myers__tests__identical_content.snap diff --git a/reconcile/src/diffs/snapshots/reconcile__diffs__myers__tests__insert_only.snap b/src/diffs/snapshots/reconcile__diffs__myers__tests__insert_only.snap similarity index 100% rename from reconcile/src/diffs/snapshots/reconcile__diffs__myers__tests__insert_only.snap rename to src/diffs/snapshots/reconcile__diffs__myers__tests__insert_only.snap diff --git a/reconcile/src/diffs/snapshots/reconcile__diffs__myers__tests__prefix_and_suffix.snap b/src/diffs/snapshots/reconcile__diffs__myers__tests__prefix_and_suffix.snap similarity index 100% rename from reconcile/src/diffs/snapshots/reconcile__diffs__myers__tests__prefix_and_suffix.snap rename to src/diffs/snapshots/reconcile__diffs__myers__tests__prefix_and_suffix.snap diff --git a/reconcile/src/lib.rs b/src/lib.rs similarity index 88% rename from reconcile/src/lib.rs rename to src/lib.rs index c621ffb..f954c77 100644 --- a/reconcile/src/lib.rs +++ b/src/lib.rs @@ -8,3 +8,6 @@ pub use operation_transformation::{ reconcile_with_tokenizer, }; pub use tokenizer::{Tokenizer, token::Token, word_tokenizer::word_tokenizer}; + +#[cfg(feature = "wasm")] +pub mod wasm; diff --git a/reconcile/src/operation_transformation.rs b/src/operation_transformation.rs similarity index 100% rename from reconcile/src/operation_transformation.rs rename to src/operation_transformation.rs diff --git a/reconcile/src/operation_transformation/cursor.rs b/src/operation_transformation/cursor.rs similarity index 100% rename from reconcile/src/operation_transformation/cursor.rs rename to src/operation_transformation/cursor.rs diff --git a/reconcile/src/operation_transformation/edited_text.rs b/src/operation_transformation/edited_text.rs similarity index 100% rename from reconcile/src/operation_transformation/edited_text.rs rename to src/operation_transformation/edited_text.rs diff --git a/reconcile/src/operation_transformation/merge_context.rs b/src/operation_transformation/merge_context.rs similarity index 100% rename from reconcile/src/operation_transformation/merge_context.rs rename to src/operation_transformation/merge_context.rs diff --git a/reconcile/src/operation_transformation/operation.rs b/src/operation_transformation/operation.rs similarity index 100% rename from reconcile/src/operation_transformation/operation.rs rename to src/operation_transformation/operation.rs diff --git a/reconcile/src/operation_transformation/ordered_operation.rs b/src/operation_transformation/ordered_operation.rs similarity index 100% rename from reconcile/src/operation_transformation/ordered_operation.rs rename to src/operation_transformation/ordered_operation.rs diff --git a/reconcile/src/operation_transformation/snapshots/reconcile__operation_transformation__edited_text__tests__calculate_operations.snap b/src/operation_transformation/snapshots/reconcile__operation_transformation__edited_text__tests__calculate_operations.snap similarity index 100% rename from reconcile/src/operation_transformation/snapshots/reconcile__operation_transformation__edited_text__tests__calculate_operations.snap rename to src/operation_transformation/snapshots/reconcile__operation_transformation__edited_text__tests__calculate_operations.snap diff --git a/reconcile/src/operation_transformation/snapshots/reconcile__operation_transformation__edited_text__tests__calculate_operations_with_no_diff.snap b/src/operation_transformation/snapshots/reconcile__operation_transformation__edited_text__tests__calculate_operations_with_no_diff.snap similarity index 100% rename from reconcile/src/operation_transformation/snapshots/reconcile__operation_transformation__edited_text__tests__calculate_operations_with_no_diff.snap rename to src/operation_transformation/snapshots/reconcile__operation_transformation__edited_text__tests__calculate_operations_with_no_diff.snap diff --git a/reconcile/src/operation_transformation/snapshots/reconcile__operations__edited_text__tests__calculate_operations.snap b/src/operation_transformation/snapshots/reconcile__operations__edited_text__tests__calculate_operations.snap similarity index 100% rename from reconcile/src/operation_transformation/snapshots/reconcile__operations__edited_text__tests__calculate_operations.snap rename to src/operation_transformation/snapshots/reconcile__operations__edited_text__tests__calculate_operations.snap diff --git a/reconcile/src/operation_transformation/snapshots/reconcile__operations__operation_sequence__tests__calculate_operations.snap b/src/operation_transformation/snapshots/reconcile__operations__operation_sequence__tests__calculate_operations.snap similarity index 100% rename from reconcile/src/operation_transformation/snapshots/reconcile__operations__operation_sequence__tests__calculate_operations.snap rename to src/operation_transformation/snapshots/reconcile__operations__operation_sequence__tests__calculate_operations.snap diff --git a/reconcile/src/operation_transformation/utils.rs b/src/operation_transformation/utils.rs similarity index 100% rename from reconcile/src/operation_transformation/utils.rs rename to src/operation_transformation/utils.rs diff --git a/reconcile/src/operation_transformation/utils/cook_operations.rs b/src/operation_transformation/utils/cook_operations.rs similarity index 100% rename from reconcile/src/operation_transformation/utils/cook_operations.rs rename to src/operation_transformation/utils/cook_operations.rs diff --git a/reconcile/src/operation_transformation/utils/elongate_operations.rs b/src/operation_transformation/utils/elongate_operations.rs similarity index 100% rename from reconcile/src/operation_transformation/utils/elongate_operations.rs rename to src/operation_transformation/utils/elongate_operations.rs diff --git a/reconcile/src/tokenizer.rs b/src/tokenizer.rs similarity index 100% rename from reconcile/src/tokenizer.rs rename to src/tokenizer.rs diff --git a/reconcile/src/tokenizer/snapshots/reconcile__tokenizer__word_tokenizer__tests__with_snapshots-2.snap b/src/tokenizer/snapshots/reconcile__tokenizer__word_tokenizer__tests__with_snapshots-2.snap similarity index 100% rename from reconcile/src/tokenizer/snapshots/reconcile__tokenizer__word_tokenizer__tests__with_snapshots-2.snap rename to src/tokenizer/snapshots/reconcile__tokenizer__word_tokenizer__tests__with_snapshots-2.snap diff --git a/reconcile/src/tokenizer/snapshots/reconcile__tokenizer__word_tokenizer__tests__with_snapshots-3.snap b/src/tokenizer/snapshots/reconcile__tokenizer__word_tokenizer__tests__with_snapshots-3.snap similarity index 100% rename from reconcile/src/tokenizer/snapshots/reconcile__tokenizer__word_tokenizer__tests__with_snapshots-3.snap rename to src/tokenizer/snapshots/reconcile__tokenizer__word_tokenizer__tests__with_snapshots-3.snap diff --git a/reconcile/src/tokenizer/snapshots/reconcile__tokenizer__word_tokenizer__tests__with_snapshots-4.snap b/src/tokenizer/snapshots/reconcile__tokenizer__word_tokenizer__tests__with_snapshots-4.snap similarity index 100% rename from reconcile/src/tokenizer/snapshots/reconcile__tokenizer__word_tokenizer__tests__with_snapshots-4.snap rename to src/tokenizer/snapshots/reconcile__tokenizer__word_tokenizer__tests__with_snapshots-4.snap diff --git a/reconcile/src/tokenizer/snapshots/reconcile__tokenizer__word_tokenizer__tests__with_snapshots-5.snap b/src/tokenizer/snapshots/reconcile__tokenizer__word_tokenizer__tests__with_snapshots-5.snap similarity index 100% rename from reconcile/src/tokenizer/snapshots/reconcile__tokenizer__word_tokenizer__tests__with_snapshots-5.snap rename to src/tokenizer/snapshots/reconcile__tokenizer__word_tokenizer__tests__with_snapshots-5.snap diff --git a/reconcile/src/tokenizer/snapshots/reconcile__tokenizer__word_tokenizer__tests__with_snapshots.snap b/src/tokenizer/snapshots/reconcile__tokenizer__word_tokenizer__tests__with_snapshots.snap similarity index 100% rename from reconcile/src/tokenizer/snapshots/reconcile__tokenizer__word_tokenizer__tests__with_snapshots.snap rename to src/tokenizer/snapshots/reconcile__tokenizer__word_tokenizer__tests__with_snapshots.snap diff --git a/reconcile/src/tokenizer/token.rs b/src/tokenizer/token.rs similarity index 100% rename from reconcile/src/tokenizer/token.rs rename to src/tokenizer/token.rs diff --git a/reconcile/src/tokenizer/word_tokenizer.rs b/src/tokenizer/word_tokenizer.rs similarity index 100% rename from reconcile/src/tokenizer/word_tokenizer.rs rename to src/tokenizer/word_tokenizer.rs diff --git a/reconcile/src/utils.rs b/src/utils.rs similarity index 100% rename from reconcile/src/utils.rs rename to src/utils.rs diff --git a/reconcile/src/utils/common_prefix_len.rs b/src/utils/common_prefix_len.rs similarity index 100% rename from reconcile/src/utils/common_prefix_len.rs rename to src/utils/common_prefix_len.rs diff --git a/reconcile/src/utils/common_suffix_len.rs b/src/utils/common_suffix_len.rs similarity index 100% rename from reconcile/src/utils/common_suffix_len.rs rename to src/utils/common_suffix_len.rs diff --git a/reconcile/src/utils/find_longest_prefix_contained_within.rs b/src/utils/find_longest_prefix_contained_within.rs similarity index 100% rename from reconcile/src/utils/find_longest_prefix_contained_within.rs rename to src/utils/find_longest_prefix_contained_within.rs diff --git a/reconcile/src/utils/side.rs b/src/utils/side.rs similarity index 100% rename from reconcile/src/utils/side.rs rename to src/utils/side.rs diff --git a/reconcile/src/utils/string_builder.rs b/src/utils/string_builder.rs similarity index 100% rename from reconcile/src/utils/string_builder.rs rename to src/utils/string_builder.rs diff --git a/src/wasm.rs b/src/wasm.rs new file mode 100644 index 0000000..43f39f5 --- /dev/null +++ b/src/wasm.rs @@ -0,0 +1,2 @@ +pub mod cursor; +pub mod lib; diff --git a/sync_lib/src/cursor.rs b/src/wasm/cursor.rs similarity index 60% rename from sync_lib/src/cursor.rs rename to src/wasm/cursor.rs index 2f7135e..9e72095 100644 --- a/sync_lib/src/cursor.rs +++ b/src/wasm/cursor.rs @@ -3,27 +3,27 @@ use wasm_bindgen::prelude::*; /// Wrapper type to expose `TextWithCursors` to JS. #[wasm_bindgen] #[derive(Debug, Clone, PartialEq)] -pub struct TextWithCursors { +pub struct JsTextWithCursors { text: String, - cursors: Vec, + cursors: Vec, } #[wasm_bindgen] -impl TextWithCursors { +impl JsTextWithCursors { #[wasm_bindgen(constructor)] #[must_use] - pub fn new(text: String, cursors: Vec) -> Self { Self { text, cursors } } + pub fn new(text: String, cursors: Vec) -> Self { Self { text, cursors } } #[must_use] pub fn text(&self) -> String { self.text.clone() } #[must_use] - pub fn cursors(&self) -> Vec { self.cursors.clone() } + pub fn cursors(&self) -> Vec { self.cursors.clone() } } -impl From for reconcile::TextWithCursors<'_> { - fn from(owned: TextWithCursors) -> Self { - reconcile::TextWithCursors::new_owned( +impl From for crate::TextWithCursors<'_> { + fn from(owned: JsTextWithCursors) -> Self { + crate::TextWithCursors::new_owned( owned.text.to_string(), owned .cursors @@ -34,9 +34,9 @@ impl From for reconcile::TextWithCursors<'_> { } } -impl From> for TextWithCursors { - fn from(text_with_cursors: reconcile::TextWithCursors<'_>) -> Self { - TextWithCursors { +impl From> for JsTextWithCursors { + fn from(text_with_cursors: crate::TextWithCursors<'_>) -> Self { + JsTextWithCursors { text: text_with_cursors.text.into_owned(), cursors: text_with_cursors .cursors @@ -50,13 +50,13 @@ impl From> for TextWithCursors { /// Wrapper type to expose `CursorPosition` to JS. #[wasm_bindgen] #[derive(Debug, Clone, PartialEq)] -pub struct CursorPosition { +pub struct JsCursorPosition { id: usize, char_index: usize, } #[wasm_bindgen] -impl CursorPosition { +impl JsCursorPosition { #[wasm_bindgen(constructor)] #[must_use] pub fn new(id: usize, char_index: usize) -> Self { Self { id, char_index } } @@ -69,18 +69,18 @@ impl CursorPosition { pub fn char_index(&self) -> usize { self.char_index } } -impl From for reconcile::CursorPosition { - fn from(owned: CursorPosition) -> Self { - reconcile::CursorPosition { +impl From for crate::CursorPosition { + fn from(owned: JsCursorPosition) -> Self { + crate::CursorPosition { id: owned.id, char_index: owned.char_index, } } } -impl From for CursorPosition { - fn from(cursor: reconcile::CursorPosition) -> Self { - CursorPosition { +impl From for JsCursorPosition { + fn from(cursor: crate::CursorPosition) -> Self { + JsCursorPosition { id: cursor.id, char_index: cursor.char_index, } diff --git a/sync_lib/src/lib.rs b/src/wasm/lib.rs similarity index 68% rename from sync_lib/src/lib.rs rename to src/wasm/lib.rs index d2a54cf..3188e1f 100644 --- a/sync_lib/src/lib.rs +++ b/src/wasm/lib.rs @@ -11,56 +11,9 @@ use core::str; -use base64::{Engine as _, engine::general_purpose::STANDARD}; -use cursor::TextWithCursors; -use errors::SyncLibError; use wasm_bindgen::prelude::*; -pub mod cursor; -pub mod errors; - -/// Encode binary data for easy transport over HTTP. Inverse of -/// `base64_to_bytes`. -/// -/// # Arguments -/// -/// - `input`: The binary data to encode. -/// -/// # Returns -/// -/// The base64-encoded string. -/// -/// # Panics -/// -/// If the input is not valid UTF-8. -#[wasm_bindgen(js_name = bytesToBase64)] -#[must_use] -pub fn bytes_to_base64(input: &[u8]) -> String { - set_panic_hook(); - - STANDARD.encode(input) -} - -/// Inverse of `bytes_to_base64`. -/// Decode base64-encoded data into binary data. -/// -/// # Arguments -/// -/// - `input`: The base64-encoded string. -/// -/// # Returns -/// -/// The decoded binary data. -/// -/// # Errors -/// -/// If the input is not valid base64. -#[wasm_bindgen(js_name = base64ToBytes)] -pub fn base64_to_bytes(input: &str) -> Result, SyncLibError> { - set_panic_hook(); - - STANDARD.decode(input).map_err(SyncLibError::from) -} +use crate::wasm::cursor::JsTextWithCursors; /// Merge two documents with a common parent. Relies on `reconcile::reconcile` /// for texts and returns the right document as-is if either of the updated @@ -87,7 +40,7 @@ pub fn merge(parent: &[u8], left: &[u8], right: &[u8]) -> Vec { if is_binary(parent) || is_binary(left) || is_binary(right) { right.to_vec() } else { - reconcile::reconcile( + crate::reconcile( str::from_utf8(parent).expect("parent must be valid UTF-8 because it's not binary"), str::from_utf8(left).expect("left must be valid UTF-8 because it's not binary"), str::from_utf8(right).expect("right must be valid UTF-8 because it's not binary"), @@ -96,13 +49,13 @@ pub fn merge(parent: &[u8], left: &[u8], right: &[u8]) -> Vec { } } -/// WASM wrapper around `reconcile::reconcile` for merging text. +/// WASM wrapper around `crate::reconcile` for merging text. #[wasm_bindgen(js_name = mergeText)] #[must_use] pub fn merge_text(parent: &str, left: &str, right: &str) -> String { set_panic_hook(); - reconcile::reconcile(parent, left, right) + crate::reconcile(parent, left, right) } /// WASM wrapper around `reconcile::reconcile_with_cursors` for merging text. @@ -110,12 +63,12 @@ pub fn merge_text(parent: &str, left: &str, right: &str) -> String { #[must_use] pub fn merge_text_with_cursors( parent: &str, - left: TextWithCursors, - right: TextWithCursors, -) -> TextWithCursors { + left: JsTextWithCursors, + right: JsTextWithCursors, +) -> JsTextWithCursors { set_panic_hook(); - reconcile::reconcile_with_cursors(parent, left.into(), right.into()).into() + crate::reconcile_with_cursors(parent, left.into(), right.into()).into() } /// Heuristically determine if the given data is a binary or a text file's diff --git a/sync_lib/Cargo.toml b/sync_lib/Cargo.toml deleted file mode 100644 index 72f3de8..0000000 --- a/sync_lib/Cargo.toml +++ /dev/null @@ -1,32 +0,0 @@ -[package] -name = "sync_lib" -version.workspace = true -edition.workspace = true -authors.workspace = true -license.workspace = true -repository.workspace = true - -[lib] -crate-type = ["cdylib", "rlib"] - -[dependencies] -base64 = "0.22.1" -reconcile = { path = "../reconcile" } -wasm-bindgen = "0.2.99" -thiserror = { workspace = true } - -# The `console_error_panic_hook` crate provides better debugging of panics by -# logging them with `console.error`. This is great for development, but requires -# all the `std::fmt` and `std::panicking` infrastructure, so isn't great for -# code size when deploying. -console_error_panic_hook = { version = "0.1.7", optional = true } - -[dev-dependencies] -wasm-bindgen-test = "0.3.49" -insta = "1.42.2" - -[features] -default = ["console_error_panic_hook"] - -[lints] -workspace = true diff --git a/sync_lib/src/errors.rs b/sync_lib/src/errors.rs deleted file mode 100644 index c09eafb..0000000 --- a/sync_lib/src/errors.rs +++ /dev/null @@ -1,29 +0,0 @@ -use base64::DecodeError; -use thiserror::Error; -use wasm_bindgen::JsValue; - -#[derive(Error, Debug)] -pub enum SyncLibError { - #[error("Base64 decoding error because of {}", .reason)] - Base64DecodingError { reason: String }, -} - -impl From for SyncLibError { - fn from(e: DecodeError) -> Self { - SyncLibError::Base64DecodingError { - reason: e.to_string(), - } - } -} - -impl From for SyncLibError { - fn from(e: std::string::FromUtf8Error) -> Self { - SyncLibError::Base64DecodingError { - reason: e.to_string(), - } - } -} - -impl From for JsValue { - fn from(val: SyncLibError) -> Self { JsValue::from_str(&val.to_string()) } -} diff --git a/sync_lib/tests/snapshots/web__base64_to_bytes_error.snap b/sync_lib/tests/snapshots/web__base64_to_bytes_error.snap deleted file mode 100644 index fa17876..0000000 --- a/sync_lib/tests/snapshots/web__base64_to_bytes_error.snap +++ /dev/null @@ -1,10 +0,0 @@ ---- -source: sync_lib/tests/web.rs -expression: base64_to_bytes(input) -snapshot_kind: text ---- -Err( - Base64DecodingError { - reason: "Invalid symbol 61, offset 0.", - }, -) diff --git a/reconcile/tests/example_document.rs b/tests/example_document.rs similarity index 100% rename from reconcile/tests/example_document.rs rename to tests/example_document.rs diff --git a/reconcile/tests/examples/README.md b/tests/examples/README.md similarity index 100% rename from reconcile/tests/examples/README.md rename to tests/examples/README.md diff --git a/reconcile/tests/examples/deletes.yml b/tests/examples/deletes.yml similarity index 100% rename from reconcile/tests/examples/deletes.yml rename to tests/examples/deletes.yml diff --git a/reconcile/tests/examples/deletes_and_inserts.yml b/tests/examples/deletes_and_inserts.yml similarity index 100% rename from reconcile/tests/examples/deletes_and_inserts.yml rename to tests/examples/deletes_and_inserts.yml diff --git a/reconcile/tests/examples/idempotent_inserts.yml b/tests/examples/idempotent_inserts.yml similarity index 100% rename from reconcile/tests/examples/idempotent_inserts.yml rename to tests/examples/idempotent_inserts.yml diff --git a/reconcile/tests/examples/multiline.yml b/tests/examples/multiline.yml similarity index 100% rename from reconcile/tests/examples/multiline.yml rename to tests/examples/multiline.yml diff --git a/reconcile/tests/examples/replacing.yml b/tests/examples/replacing.yml similarity index 100% rename from reconcile/tests/examples/replacing.yml rename to tests/examples/replacing.yml diff --git a/reconcile/tests/examples/utf-8.yml b/tests/examples/utf-8.yml similarity index 100% rename from reconcile/tests/examples/utf-8.yml rename to tests/examples/utf-8.yml diff --git a/reconcile/tests/examples/various.yml b/tests/examples/various.yml similarity index 100% rename from reconcile/tests/examples/various.yml rename to tests/examples/various.yml diff --git a/reconcile/tests/resources/blns.txt b/tests/resources/blns.txt similarity index 100% rename from reconcile/tests/resources/blns.txt rename to tests/resources/blns.txt diff --git a/reconcile/tests/resources/kun_lu.txt b/tests/resources/kun_lu.txt similarity index 100% rename from reconcile/tests/resources/kun_lu.txt rename to tests/resources/kun_lu.txt diff --git a/reconcile/tests/resources/pride_and_prejudice.txt b/tests/resources/pride_and_prejudice.txt similarity index 100% rename from reconcile/tests/resources/pride_and_prejudice.txt rename to tests/resources/pride_and_prejudice.txt diff --git a/reconcile/tests/resources/room_with_a_view.txt b/tests/resources/room_with_a_view.txt similarity index 100% rename from reconcile/tests/resources/room_with_a_view.txt rename to tests/resources/room_with_a_view.txt diff --git a/reconcile/tests/test.rs b/tests/test.rs similarity index 100% rename from reconcile/tests/test.rs rename to tests/test.rs diff --git a/sync_lib/tests/web.rs b/tests/web.rs similarity index 67% rename from sync_lib/tests/web.rs rename to tests/web.rs index cf82aa7..e5db786 100644 --- a/sync_lib/tests/web.rs +++ b/tests/web.rs @@ -1,30 +1,10 @@ use insta::assert_debug_snapshot; -use sync_lib::{ - cursor::{CursorPosition, TextWithCursors}, - *, +use reconcile::wasm::{ + cursor::{JsCursorPosition, JsTextWithCursors}, + lib::{is_binary, is_file_type_mergable, merge, merge_text, merge_text_with_cursors}, }; use wasm_bindgen_test::*; -#[wasm_bindgen_test(unsupported = test)] -fn test_bytes_to_base64() { - let input = b"hello"; - let expected = "aGVsbG8="; - assert_eq!(bytes_to_base64(input), expected); -} - -#[wasm_bindgen_test(unsupported = test)] -fn test_base64_to_bytes() { - let input = "aGVsbG8="; - let expected = b"hello".to_vec(); - assert_eq!(base64_to_bytes(input).unwrap(), expected); -} - -#[test] // insta doesn't support wasm-bindgen-test -fn test_base64_to_bytes_error() { - let input = "==="; - assert_debug_snapshot!(base64_to_bytes(input)); -} - #[wasm_bindgen_test(unsupported = test)] fn test_merge() { let left = b"hello "; @@ -50,18 +30,18 @@ fn test_merge_text() { fn test_merge_text_with_cursors() { let result = merge_text_with_cursors( "hi", - TextWithCursors::new("hi world".to_owned(), vec![]), - TextWithCursors::new( + JsTextWithCursors::new("hi world".to_owned(), vec![]), + JsTextWithCursors::new( "hi".to_owned(), - vec![CursorPosition::new(0, 1), CursorPosition::new(1, 2)], + vec![JsCursorPosition::new(0, 1), JsCursorPosition::new(1, 2)], ), ); assert_eq!( result, - TextWithCursors::new( + JsTextWithCursors::new( "hi world".to_owned(), - vec![CursorPosition::new(0, 1), CursorPosition::new(1, 2)] + vec![JsCursorPosition::new(0, 1), JsCursorPosition::new(1, 2)] ), ); }