Skip to content
Merged
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
214 changes: 112 additions & 102 deletions main.js

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
},
"dependencies": {
"@callumalpass/mdbase-interop": "file:vendor/callumalpass-mdbase-interop-0.1.0-rc.2.tgz",
"@mdbase/connect-protocol": "file:vendor/mdbase-connect-protocol-0.1.0-beta.11.tgz",
"@mdbase/connect-sync": "file:vendor/mdbase-connect-sync-0.1.0-beta.11.tgz",
"@mdbase/connect-protocol": "file:vendor/mdbase-connect-protocol-0.1.0-beta.21-35c137579861.tgz",
"@mdbase/connect-sync": "file:vendor/mdbase-connect-sync-0.1.0-beta.21-35c137579861.tgz",
"ajv": "^8.20.0",
"ajv-formats": "^3.0.1",
"picomatch": "^4.0.5"
Expand Down
10 changes: 1 addition & 9 deletions src/connectSync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ import {
isExcluded,
loadMdbaseConfig,
normalizeSafeRelativePath,
parseFrontmatter,
} from "./mdbaseCore";

export interface MirrorProfile {
Expand Down Expand Up @@ -642,8 +641,8 @@ export class ConnectSyncController {
const prepared = marker.phase === "waiting_for_approval"
? await this.adoptionClient.waitForApproval(session, callbacks)
: await this.requirePreparedAdoption(session, callbacks);
await this.updateAdoptionPhase("uploading");
const warmSnapshot = await this.captureAuthoritySnapshot(session.requested.collectionId);
await this.updateAdoptionPhase("uploading");
await this.adoptionClient.uploadSnapshot(session, prepared, warmSnapshot, callbacks);

// From this point local plugin writes are stopped. Any external file edit is
Expand Down Expand Up @@ -784,13 +783,6 @@ export class ConnectSyncController {
const path = normalizePath(file.path);
if (isExcluded(path, config)) continue;
const document = await this.app.vault.cachedRead(file);
const parsed = parseFrontmatter(document);
if (parsed.error) {
throw new SyncError(
"invalid_authority_record",
`${path} has invalid frontmatter: ${parsed.error}`,
);
}
records.push({
path,
document,
Expand Down
8 changes: 7 additions & 1 deletion test/connectSync.adoption.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,8 @@ const callbacks = {

test("adopts every canonical resource and retains the existing vault as a mirror", async () => {
const { vault, settings, adoption, controller, collectionId } = await fixture();
const opaqueDocument = "---\ntitle: [unterminated\n---\nOpaque body\n";
await vault.put("tasks/opaque.md", opaqueDocument);
const profile = await controller.adoptLocalCollection({
controlUrl: "https://connect.example",
mirrorName: "Obsidian",
Expand All @@ -348,7 +350,11 @@ test("adopts every canonical resource and retains the existing vault as a mirror
["view", "views/tasks.base"],
],
);
assert.equal(final.records[0]?.path, "tasks/one.md");
assert.deepEqual(final.records.map(({ path }) => path), ["tasks/one.md", "tasks/opaque.md"]);
assert.equal(
final.records.find(({ path }) => path === "tasks/opaque.md")?.document,
opaqueDocument,
);
assert.equal(await vault.adapter.exists(".mdbase/connect-role.json"), true);
assert.equal(await vault.adapter.exists(".mdbase/authority-adoption.json"), false);
assert.equal(await vault.adapter.exists(".mdbase/authority-adoption-snapshot.json"), false);
Expand Down
11 changes: 9 additions & 2 deletions test/v3-foundations.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as assert from "node:assert/strict";
import { createHash } from "node:crypto";
import { performance } from "node:perf_hooks";
import { test } from "node:test";
import { normalizePath, TFile, TFolder } from "obsidian";
Expand Down Expand Up @@ -40,6 +41,10 @@ interface StoredFile {
const TestFile = TFile as unknown as { new (path: string): TFile };
const TestFolder = TFolder as unknown as { new (path: string): TFolder };

function sha256Revision(document: string): string {
return `sha256:${createHash("sha256").update(document).digest("hex")}`;
}

class MemoryVault {
readonly files = new Map<string, StoredFile>();
readonly folders = new Map<string, TFolder>();
Expand Down Expand Up @@ -745,6 +750,8 @@ test("device lease rejects concurrent mirror ownership and releases after failur
});

test("portable mirror materializes resources and records through Obsidian Vault APIs", async () => {
const configuration = "spec_version: 0.3.0\n";
const noteType = "---\nkind: mdbase.type\n---\n";
const hosted = new MemoryAuthority({
snapshotPageSize: 1,
resources: {
Expand All @@ -753,8 +760,8 @@ test("portable mirror materializes resources and records through Obsidian Vault
types: [],
contracts: [],
documents: [
{ path: "mdbase.yaml", kind: "configuration", revision: "config-1", document: "spec_version: 0.3.0\n" },
{ path: "_types/note.md", kind: "type", revision: "type-1", document: "---\nkind: mdbase.type\n---\n" },
{ path: "mdbase.yaml", kind: "configuration", revision: sha256Revision(configuration), document: configuration },
{ path: "_types/note.md", kind: "type", revision: sha256Revision(noteType), document: noteType },
],
},
});
Expand Down
Binary file not shown.
14 changes: 7 additions & 7 deletions vendor/mdbase-connect-sdk.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
{
"schema_version": 1,
"repository": "https://github.com/mdbase-dev/mdbase-connect",
"revision": "c3a44aa7063a7bae1bbf89bbc8c5d7e868a95119",
"revision": "35c137579861e49baaec4029eaa9d18a43442e5e",
"artifacts": [
{
"package": "protocol",
"file": "mdbase-connect-protocol-0.1.0-beta.8-c3a44aa7063a.tgz",
"bytes": 10859,
"sha512": "J7RWdFJrQsPWFEEsLG167SuV4n+bXRDFlTnlyGXlLAZblDw3Va0XUAnb2t86C9NiOys/yVIJptwtUXfrfbxjKg=="
"file": "mdbase-connect-protocol-0.1.0-beta.21-35c137579861.tgz",
"bytes": 15956,
"sha512": "sFIQ/QH4KLkzlBTqfObjnQgpsbvArYqMSApCX98U2BqeBHG02PdQz6vkIH5iS4Cf0SnD4b5eA1ONe+An2h1xWw=="
},
{
"package": "sync",
"file": "mdbase-connect-sync-0.1.0-beta.8-c3a44aa7063a.tgz",
"bytes": 49854,
"sha512": "dEiX+rSYwLJ60nngsBGCQLmqq1Os7GEul5DFutCKj5oz98uW0hx7UPRA3R14TrcQZogyHZTl/eBSrfGcWuCPaA=="
"file": "mdbase-connect-sync-0.1.0-beta.21-35c137579861.tgz",
"bytes": 61361,
"sha512": "XFswT6qADLJlLwip27PN8khBBH46APpjnXM3qWfhZE1ZLdOJ9oRGSvgnupMRMwyuhSCf0Jy/aUvgbkQcNOesRg=="
}
]
}
Binary file not shown.
Loading