Remove sync-lib
This commit is contained in:
parent
0ce5787858
commit
da60f8c005
24 changed files with 67 additions and 443 deletions
|
|
@ -23,7 +23,6 @@
|
|||
"@types/node": "^22.15.30",
|
||||
"jest": "^29.7.0",
|
||||
"reconcile-text": "^0.4.10",
|
||||
"sync_lib": "file:../../backend/sync_lib/pkg",
|
||||
"ts-jest": "^29.3.4",
|
||||
"ts-loader": "^9.5.2",
|
||||
"tslib": "2.8.1",
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ import { FileOperations } from "./file-operations";
|
|||
import { Logger } from "../tracing/logger";
|
||||
import { assertSetContainsExactly } from "../utils/assert-set-contains-exactly";
|
||||
import type { FileSystemOperations } from "./filesystem-operations";
|
||||
import init from "sync_lib";
|
||||
import fs from "fs";
|
||||
import { TextWithCursors } from "reconcile-text";
|
||||
|
||||
|
|
@ -73,13 +72,6 @@ class FakeFileSystemOperations implements FileSystemOperations {
|
|||
}
|
||||
|
||||
describe("File operations", () => {
|
||||
beforeEach(async () => {
|
||||
const wasmBin = fs.readFileSync(
|
||||
"../../backend/sync_lib/pkg/sync_lib_bg.wasm"
|
||||
);
|
||||
await init({ module_or_path: wasmBin });
|
||||
});
|
||||
|
||||
it("should deconflict renames", async () => {
|
||||
const fileSystemOperations = new FakeFileSystemOperations();
|
||||
const fileOperations = new FileOperations(
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
import type { Logger } from "../tracing/logger";
|
||||
import type { FileSystemOperations } from "./filesystem-operations";
|
||||
import type { Database, RelativePath } from "../persistence/database";
|
||||
import { isFileTypeMergable } from "sync_lib";
|
||||
import { SafeFileSystemOperations } from "./safe-filesystem-operations";
|
||||
import type { TextWithCursors } from "reconcile-text";
|
||||
import { isBinary, reconcile } from "reconcile-text";
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
import initWasm from "sync_lib";
|
||||
import wasmBin from "../../../backend/sync_lib/pkg/sync_lib_bg.wasm";
|
||||
import type { PersistenceProvider } from "./persistence/persistence";
|
||||
import type { HistoryEntry, HistoryStats } from "./tracing/sync-history";
|
||||
import { SyncHistory } from "./tracing/sync-history";
|
||||
|
|
|
|||
|
|
@ -1,18 +0,0 @@
|
|||
import init, { base64ToBytes } from "sync_lib";
|
||||
import fs from "fs";
|
||||
|
||||
describe("deserialize", () => {
|
||||
it("should serialize a Uint8Array to a base64 string", async () => {
|
||||
const wasmBin = fs.readFileSync(
|
||||
"../../backend/sync_lib/pkg/sync_lib_bg.wasm"
|
||||
);
|
||||
await init({ module_or_path: wasmBin });
|
||||
|
||||
const base64 = "SGVsbG8=";
|
||||
const jsResult = base64ToBytes(base64);
|
||||
const expected = new Uint8Array([72, 101, 108, 108, 111]);
|
||||
expect(jsResult).toEqual(expected);
|
||||
const rustResult = base64ToBytes(base64);
|
||||
expect(jsResult).toEqual(rustResult);
|
||||
});
|
||||
});
|
||||
28
frontend/sync-client/src/utils/is-file-type-mergable.test.ts
Normal file
28
frontend/sync-client/src/utils/is-file-type-mergable.test.ts
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
import { isFileTypeMergable } from "./is-file-type-mergable";
|
||||
|
||||
describe("isFileTypeMergable", () => {
|
||||
it("should return true for .md files", () => {
|
||||
expect(isFileTypeMergable(".md")).toBe(true);
|
||||
expect(isFileTypeMergable("hi.md")).toBe(true);
|
||||
expect(isFileTypeMergable("my/path/to/my/document.md")).toBe(true);
|
||||
});
|
||||
|
||||
it("should return true for .txt files", () => {
|
||||
expect(isFileTypeMergable(".txt")).toBe(true);
|
||||
expect(isFileTypeMergable("hi.txt")).toBe(true);
|
||||
expect(isFileTypeMergable("my/path/to/my/document.txt")).toBe(true);
|
||||
});
|
||||
|
||||
it("should be case insensitive", () => {
|
||||
expect(isFileTypeMergable("hi.MD")).toBe(true);
|
||||
expect(isFileTypeMergable("my/path/to/my/DOCUMENT.MD")).toBe(true);
|
||||
expect(isFileTypeMergable("hi.TXT")).toBe(true);
|
||||
expect(isFileTypeMergable("my/path/to/my/DOCUMENT.TXT")).toBe(true);
|
||||
});
|
||||
|
||||
it("should return false for non-mergable file types", () => {
|
||||
expect(isFileTypeMergable(".json")).toBe(false);
|
||||
expect(isFileTypeMergable("HELLO.JSON")).toBe(false);
|
||||
expect(isFileTypeMergable("my/config.yml")).toBe(false);
|
||||
});
|
||||
});
|
||||
6
frontend/sync-client/src/utils/is-file-type-mergable.ts
Normal file
6
frontend/sync-client/src/utils/is-file-type-mergable.ts
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
export function isFileTypeMergable(pathOrFileName: string): boolean {
|
||||
const parts = pathOrFileName.split(".");
|
||||
const fileExtension = parts.at(-1) || "";
|
||||
|
||||
return ["md", "txt"].includes(fileExtension.toLowerCase());
|
||||
}
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
import { serialize } from "./serialize";
|
||||
import init, { bytesToBase64 } from "sync_lib";
|
||||
import fs from "fs";
|
||||
|
||||
describe("serialize", () => {
|
||||
it("should serialize a Uint8Array to a base64 string", async () => {
|
||||
const wasmBin = fs.readFileSync(
|
||||
"../../backend/sync_lib/pkg/sync_lib_bg.wasm"
|
||||
);
|
||||
await init({ module_or_path: wasmBin });
|
||||
|
||||
const data = new Uint8Array([72, 101, 108, 108, 111]);
|
||||
const jsResult = serialize(data);
|
||||
const rustResult = bytesToBase64(data);
|
||||
expect(rustResult).toBe("SGVsbG8=");
|
||||
expect(jsResult).toBe(rustResult);
|
||||
});
|
||||
});
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
import { bytesToBase64 } from "byte-base64";
|
||||
|
||||
export function serialize(data: Uint8Array): string {
|
||||
return bytesToBase64(data);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue