mirror of
https://github.com/vrtmrz/obsidian-livesync.git
synced 2026-11-15 12:40:12 +00:00
refactor: organise source files by ownership
Separate host-independent helpers under common/core and colocate feature support code with its owners. Update imports, tests, and source-layout guidance while preserving runtime behaviour.
This commit is contained in:
1 parent
9a0941647b
commit
73adfe3a74
115 files changed
+115
-103
No files matched your search
@@ -47,7 +47,7 @@ vi.mock("@/common/events.ts", () => ({
|
||||
vi.mock("@/common/translation", () => ({
|
||||
$msg: vi.fn((message: string) => message),
|
||||
}));
|
||||
vi.mock("@/common/obsidianCommunityPlugins.ts", () => ({
|
||||
vi.mock("@/features/HiddenFileCommon/obsidianCommunityPlugins.ts", () => ({
|
||||
getObsidianCommunityPluginManager: vi.fn(),
|
||||
}));
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ vi.mock("@/common/events.ts", () => ({
|
||||
vi.mock("@/common/translation", () => ({
|
||||
$msg: vi.fn((message: string) => message),
|
||||
}));
|
||||
vi.mock("@/common/obsidianCommunityPlugins.ts", () => ({
|
||||
vi.mock("@/features/HiddenFileCommon/obsidianCommunityPlugins.ts", () => ({
|
||||
getObsidianCommunityPluginManager: vi.fn(),
|
||||
}));
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ vi.mock("@/common/events.ts", () => ({
|
||||
eventHub: { onEvent: vi.fn() },
|
||||
}));
|
||||
vi.mock("@/common/translation", () => ({ $msg: (message: string) => message }));
|
||||
vi.mock("@/common/obsidianCommunityPlugins.ts", () => ({ getObsidianCommunityPluginManager: vi.fn() }));
|
||||
vi.mock("@/features/HiddenFileCommon/obsidianCommunityPlugins.ts", () => ({ getObsidianCommunityPluginManager: vi.fn() }));
|
||||
|
||||
import type { FilePathWithPrefix } from "@vrtmrz/livesync-commonlib/compat/common/types";
|
||||
import { createOptionalFileSyncDatabase, optionalFileEntry } from "../../../test/fixtures/optionalFileSyncDatabase";
|
||||
|
||||
@@ -47,7 +47,7 @@ vi.mock("@/common/events.ts", () => ({
|
||||
vi.mock("@/common/translation", () => ({
|
||||
$msg: vi.fn((message: string) => message),
|
||||
}));
|
||||
vi.mock("@/common/obsidianCommunityPlugins.ts", () => ({
|
||||
vi.mock("@/features/HiddenFileCommon/obsidianCommunityPlugins.ts", () => ({
|
||||
getObsidianCommunityPluginManager: vi.fn(),
|
||||
}));
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ vi.mock("@/common/events.ts", () => ({
|
||||
vi.mock("@/common/translation", () => ({
|
||||
$msg: vi.fn((message: string) => message),
|
||||
}));
|
||||
vi.mock("@/common/obsidianCommunityPlugins.ts", () => ({
|
||||
vi.mock("@/features/HiddenFileCommon/obsidianCommunityPlugins.ts", () => ({
|
||||
getObsidianCommunityPluginManager: vi.fn(),
|
||||
}));
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ vi.mock("@/common/events.ts", () => ({
|
||||
eventHub: { onEvent: vi.fn() },
|
||||
}));
|
||||
vi.mock("@/common/translation", () => ({ $msg: (message: string) => message }));
|
||||
vi.mock("@/common/obsidianCommunityPlugins.ts", () => ({ getObsidianCommunityPluginManager: vi.fn() }));
|
||||
vi.mock("@/features/HiddenFileCommon/obsidianCommunityPlugins.ts", () => ({ getObsidianCommunityPluginManager: vi.fn() }));
|
||||
|
||||
import { get } from "svelte/store";
|
||||
import { getDocData } from "@vrtmrz/livesync-commonlib/compat/common/utils";
|
||||
|
||||
@@ -43,7 +43,7 @@ vi.mock("@/common/events.ts", () => ({
|
||||
vi.mock("@/common/translation", () => ({
|
||||
$msg: vi.fn((message: string) => message),
|
||||
}));
|
||||
vi.mock("@/common/obsidianCommunityPlugins.ts", () => ({
|
||||
vi.mock("@/features/HiddenFileCommon/obsidianCommunityPlugins.ts", () => ({
|
||||
getObsidianCommunityPluginManager: vi.fn(),
|
||||
}));
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ vi.mock("@/common/events.ts", () => ({
|
||||
vi.mock("@/common/translation", () => ({
|
||||
$msg: vi.fn((message: string) => message),
|
||||
}));
|
||||
vi.mock("@/common/obsidianCommunityPlugins.ts", () => ({
|
||||
vi.mock("@/features/HiddenFileCommon/obsidianCommunityPlugins.ts", () => ({
|
||||
getObsidianCommunityPluginManager: vi.fn(),
|
||||
}));
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ import type { InjectableServiceHub } from "@vrtmrz/livesync-commonlib/compat/ser
|
||||
import type { LiveSyncCore } from "@/main.ts";
|
||||
import { LiveSyncError } from "@vrtmrz/livesync-commonlib/compat/common/LSError";
|
||||
import type { OptionalSyncFeatureMode } from "@/features/optionalSyncFeatures.ts";
|
||||
import { getObsidianCommunityPluginManager } from "@/common/obsidianCommunityPlugins.ts";
|
||||
import { getObsidianCommunityPluginManager } from "@/features/HiddenFileCommon/obsidianCommunityPlugins.ts";
|
||||
import { createModificationHandler } from "octagonal-wheels/modification";
|
||||
|
||||
import type { HandlerOutcome } from "@vrtmrz/livesync-commonlib/compat/services/lib/HandlerUtils";
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
import type { App, PluginManifest } from "@/deps.ts";
|
||||
|
||||
export interface ObsidianCommunityPluginManager {
|
||||
enabledPlugins: ReadonlySet<string>;
|
||||
manifests: PluginManifest[];
|
||||
loadPlugin(pluginId: string): Promise<void>;
|
||||
unloadPlugin(pluginId: string): Promise<void>;
|
||||
}
|
||||
|
||||
function isRecord(value: unknown): value is Record<string, unknown> {
|
||||
return typeof value === "object" && value !== null;
|
||||
}
|
||||
|
||||
function isPluginManifest(value: unknown): value is PluginManifest {
|
||||
return (
|
||||
isRecord(value) &&
|
||||
typeof value.id === "string" &&
|
||||
typeof value.name === "string" &&
|
||||
(value.dir === undefined || typeof value.dir === "string")
|
||||
);
|
||||
}
|
||||
|
||||
function isStringSet(value: unknown): value is ReadonlySet<string> {
|
||||
if (!(value instanceof Set)) {
|
||||
return false;
|
||||
}
|
||||
const entries = value as ReadonlySet<unknown>;
|
||||
for (const entry of entries) {
|
||||
if (typeof entry !== "string") {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
async function invokeLifecycleMethod(
|
||||
manager: Record<string, unknown>,
|
||||
methodName: "loadPlugin" | "unloadPlugin",
|
||||
pluginId: string
|
||||
): Promise<void> {
|
||||
const method = manager[methodName];
|
||||
if (typeof method !== "function") {
|
||||
throw new TypeError(`Obsidian does not expose ${methodName}`);
|
||||
}
|
||||
const result: unknown = Reflect.apply(method, manager, [pluginId]);
|
||||
await result;
|
||||
}
|
||||
|
||||
export function getObsidianCommunityPluginManager(app: App): ObsidianCommunityPluginManager {
|
||||
const managerValue: unknown = Reflect.get(app, "plugins");
|
||||
if (!isRecord(managerValue) || !isRecord(managerValue.manifests) || !isStringSet(managerValue.enabledPlugins)) {
|
||||
throw new TypeError("Obsidian does not expose the community plug-in manager");
|
||||
}
|
||||
|
||||
const manifests = Object.values(managerValue.manifests).filter(isPluginManifest);
|
||||
return {
|
||||
enabledPlugins: managerValue.enabledPlugins,
|
||||
manifests,
|
||||
loadPlugin: async (pluginId) => await invokeLifecycleMethod(managerValue, "loadPlugin", pluginId),
|
||||
unloadPlugin: async (pluginId) => await invokeLifecycleMethod(managerValue, "unloadPlugin", pluginId),
|
||||
};
|
||||
}
|
||||
@@ -59,7 +59,7 @@ import type { OptionalFileEventOptions } from "@vrtmrz/livesync-commonlib/compat
|
||||
import { configureHiddenFileSyncMode, type ConfigureHiddenFileSyncResult } from "./configureHiddenFileSyncMode.ts";
|
||||
import { performBatchWithProgress } from "./performBatchWithProgress.ts";
|
||||
import type { OptionalSyncFeatureMode } from "@/features/optionalSyncFeatures.ts";
|
||||
import { getObsidianCommunityPluginManager } from "@/common/obsidianCommunityPlugins.ts";
|
||||
import { getObsidianCommunityPluginManager } from "@/features/HiddenFileCommon/obsidianCommunityPlugins.ts";
|
||||
import { $msg } from "@/common/translation";
|
||||
type SyncDirection = "push" | "pull" | "safe" | "pullForce" | "pushForce";
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Menu, WorkspaceLeaf } from "@/deps.ts";
|
||||
import ReplicatorPaneComponent from "./P2PReplicatorPane.svelte";
|
||||
import { mount } from "svelte";
|
||||
import { SvelteItemView } from "@/common/SvelteItemView.ts";
|
||||
import { SvelteItemView } from "@/modules/coreObsidian/UI/SvelteItemView.ts";
|
||||
|
||||
import { unique } from "octagonal-wheels/collection";
|
||||
import { LOG_LEVEL_NOTICE, REMOTE_P2P } from "@vrtmrz/livesync-commonlib/compat/common/types";
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { WorkspaceLeaf } from "@/deps.ts";
|
||||
import { mount } from "svelte";
|
||||
import { SvelteItemView } from "@/common/SvelteItemView.ts";
|
||||
import { SvelteItemView } from "@/modules/coreObsidian/UI/SvelteItemView.ts";
|
||||
import type { LiveSyncBaseCore } from "@/LiveSyncBaseCore.ts";
|
||||
import type { P2PServiceViews } from "@vrtmrz/livesync-commonlib/p2p";
|
||||
import P2PServerStatusPane from "./P2PServerStatusPane.svelte";
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { ObsidianLiveSyncSettings, SettingsMigrationState } from "@vrtmrz/livesync-commonlib/settings";
|
||||
import type { CompatibilityPause } from "@/common/databaseCompatibility.ts";
|
||||
import type { CompatibilityPause } from "@/serviceFeatures/compatibilityReview.evaluation.ts";
|
||||
import type { ReviewHarnessScenarioResult, ReviewHarnessScenarioStatus } from "./reviewHarnessTypes";
|
||||
|
||||
export type { ReviewHarnessScenarioResult, ReviewHarnessScenarioStatus } from "./reviewHarnessTypes";
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { NEW_VAULT_SETTINGS, type SettingsMigrationState } from "@vrtmrz/livesync-commonlib/settings";
|
||||
import type { CompatibilityPause } from "@/common/databaseCompatibility.ts";
|
||||
import type { CompatibilityPause } from "@/serviceFeatures/compatibilityReview.evaluation.ts";
|
||||
import {
|
||||
REVIEW_HARNESS_SCENARIOS,
|
||||
REVIEW_HARNESS_SCENARIO_IDS,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { ObsidianLiveSyncSettings, SettingsMigrationState } from "@vrtmrz/livesync-commonlib/settings";
|
||||
import type { CompatibilityPause } from "@/common/databaseCompatibility.ts";
|
||||
import type { CompatibilityPause } from "@/serviceFeatures/compatibilityReview.evaluation.ts";
|
||||
import {
|
||||
REVIEW_HARNESS_SCENARIOS,
|
||||
REVIEW_HARNESS_STATE_KEY,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { NEW_VAULT_SETTINGS, type SettingsMigrationState } from "@vrtmrz/livesync-commonlib/settings";
|
||||
import type { CompatibilityPause } from "@/common/databaseCompatibility.ts";
|
||||
import type { CompatibilityPause } from "@/serviceFeatures/compatibilityReview.evaluation.ts";
|
||||
import { ReviewHarnessController, type ReviewHarnessRuntime } from "./reviewHarnessController";
|
||||
|
||||
function migration(): SettingsMigrationState {
|
||||
|
||||
Reference in new issue
Block a user