mirror of
https://github.com/vrtmrz/obsidian-livesync.git
synced 2026-07-23 13:02:58 +00:00
refactor: inject CLI I/O and diagnostics
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
import { eventHub } from "@/common/events";
|
||||
import { translateLiveSyncMessage } from "@/common/translation";
|
||||
import { ServiceContext } from "@vrtmrz/livesync-commonlib/context";
|
||||
import { ServiceContext, type StandardIo } from "@vrtmrz/livesync-commonlib/context";
|
||||
|
||||
/** Host capabilities owned by one Self-hosted LiveSync CLI composition. */
|
||||
export class NodeServiceContext extends ServiceContext {
|
||||
constructor(readonly databasePath: string) {
|
||||
constructor(
|
||||
readonly databasePath: string,
|
||||
readonly standardIo: StandardIo
|
||||
) {
|
||||
super({ events: eventHub, translate: translateLiveSyncMessage });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,12 +9,19 @@ import {
|
||||
} from "../../../../test/contracts/serviceContext";
|
||||
import { NodeServiceContext } from "./NodeServiceContext";
|
||||
import { NodeServiceHub } from "./NodeServiceHub";
|
||||
import type { StandardIo } from "@vrtmrz/livesync-commonlib/context";
|
||||
|
||||
const TRANSLATION_KEY = "Replicator.Message.InitialiseFatalError";
|
||||
|
||||
describe("NodeServiceContext contract", () => {
|
||||
it("preserves the CLI capabilities and host-neutral API results", () => {
|
||||
const context = new NodeServiceContext("/tmp/livesync-context-contract");
|
||||
const standardIo: StandardIo = {
|
||||
readStdin: async () => "input",
|
||||
prompt: async () => "answer",
|
||||
writeStdout: () => undefined,
|
||||
writeStderr: () => undefined,
|
||||
};
|
||||
const context = new NodeServiceContext("/tmp/livesync-context-contract", standardIo);
|
||||
|
||||
expect(observeServiceContext(context, TRANSLATION_KEY)).toEqual({
|
||||
translation: translateLiveSyncMessage(TRANSLATION_KEY),
|
||||
@@ -22,6 +29,7 @@ describe("NodeServiceContext contract", () => {
|
||||
});
|
||||
expect(context.events).toBe(eventHub);
|
||||
expect(context.databasePath).toBe("/tmp/livesync-context-contract");
|
||||
expect(context.standardIo).toBe(standardIo);
|
||||
|
||||
const hub = new NodeServiceHub(context.databasePath, context);
|
||||
const composition = observeServiceComposition(hub, context);
|
||||
|
||||
@@ -86,7 +86,7 @@ class NodeUIService<T extends ServiceContext> extends UIService<T> {
|
||||
}
|
||||
|
||||
export class NodeServiceHub<T extends NodeServiceContext> extends InjectableServiceHub<T> {
|
||||
constructor(basePath: string, context: T = new NodeServiceContext(basePath) as T) {
|
||||
constructor(basePath: string, context: T) {
|
||||
const runtimeDir = nodePath.join(basePath, ".livesync", "runtime");
|
||||
const localStoragePath = nodePath.join(runtimeDir, "local-storage.json");
|
||||
const keyValueDBPath = nodePath.join(runtimeDir, "keyvalue-db.json");
|
||||
|
||||
Reference in New Issue
Block a user