Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

genesis block --- or mergable by default #352

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/crdt-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export async function getValueFromCrdt<T extends DocTypes>(
): Promise<DocValue<T>> {
if (!head.length) throw logger.Debug().Msg("Getting from an empty ledger").AsError();
const link = await get(blocks, head, key);
if (!link) throw logger.Error().Str("key", key).Msg(`Missing key`).AsError();
if (!link) throw logger.Error().Str("key", key).Msg(`Not found`).AsError();
return await getValueFromLink(blocks, link, logger);
}

Expand Down
20 changes: 19 additions & 1 deletion tests/fireproof/fireproof.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
index,
isLedger,
} from "@fireproof/core";
import { NotFoundError } from "ipfs-unixfs-exporter";

export function carLogIncludesGroup(list: bs.AnyLink[], cid: CID) {
return list.some((c) => c.equals(cid));
Expand Down Expand Up @@ -45,7 +46,7 @@ describe("dreamcode", function () {
});
beforeEach(async function () {
await sthis.start();
db = fireproof("test-db");
db = fireproof("test-db", { public: true });
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not the correct way to configure public:true but we should probably make this work instead of requiring the keyname trick

ok = await db.put({ _id: "test-1", text: "fireproof", dream: true });
doc = await db.get(ok.id);
result = await db.query("text", { range: ["a", "z"] });
Expand All @@ -70,6 +71,23 @@ describe("dreamcode", function () {
expect(result.rows.length).toBe(1);
expect(result.rows[0].key).toBe(true);
});
it("should merge with another ledger", async function () {
const db2 = fireproof("test-db2", { public: true });
await db2.put<Doc>({ _id: "test-2", text: "fireproof", dream: false });
// const doc1NotFound = await db2.get("test-1").catch((e: Error) => e);
expect(db2.get("test-1")).rejects.toBeInstanceOf(NotFoundError)
// const doc2NotFound = await db.get("test-2").catch((e: Error) => e);
expect(db.get("test-2")).rejects.toBeInstanceOf(NotFoundError)
// todo, sync both of them with the same remote
await db2.put<Doc>({ _id: "test-2", text: "fireproof", dream: false });

const doc1Found = await db2.get<Doc>("test-1");
expect(doc1Found.text).toBe("fireproof");
expect(doc1Found.dream).toBe(true);
const doc2Found = await db.get<Doc>("test-2");
expect(doc2Found.text).toBe("fireproof");
expect(doc2Found.dream).toBe(false);
});
});

describe("public API", function () {
Expand Down
Loading