mirror of
https://github.com/vrtmrz/obsidian-livesync.git
synced 2026-11-05 15:58:19 +00:00
Replace broad entry inputs with the information used by file processing, history, and JSON comparison. Separate customisation content and save-base results from database-document models, and keep content fields out of logical-deletion Metadata while preserving the parent revision. Record the accepted design, compatibility boundaries, and verification. Requires Commonlib commit 751b29a74340da57122b8ab11b80d00c40272120. The registry dependency remains at 0.2.3 pending publication and adoption.
95 lines
2.9 KiB
TypeScript
95 lines
2.9 KiB
TypeScript
import { LOG_LEVEL_VERBOSE } from "octagonal-wheels/common/logger";
|
|
import {
|
|
LOG_LEVEL_INFO,
|
|
LOG_LEVEL_NOTICE,
|
|
type DocumentID,
|
|
type FilePath,
|
|
type FilePathWithPrefix,
|
|
type LOG_LEVEL,
|
|
} from "@vrtmrz/livesync-commonlib/compat/common/types";
|
|
import type { DocumentPathRef } from "@vrtmrz/livesync-commonlib/documents";
|
|
import { MARK_DONE } from "@/modules/features/ModuleLog.ts";
|
|
import type { LiveSyncCore } from "@/main.ts";
|
|
// import { __$checkInstanceBinding } from "@vrtmrz/livesync-commonlib/compat/dev/checks";
|
|
import { createInstanceLogFunction } from "@vrtmrz/livesync-commonlib/compat/services/lib/logUtils";
|
|
|
|
let noticeIndex = 0;
|
|
export abstract class LiveSyncCommands {
|
|
core: LiveSyncCore;
|
|
get app() {
|
|
return this.services.context.app;
|
|
}
|
|
get settings() {
|
|
return this.core.settings;
|
|
}
|
|
get localDatabase() {
|
|
return this.core.localDatabase;
|
|
}
|
|
get services() {
|
|
return this.core.services;
|
|
}
|
|
|
|
async path2id(filename: FilePathWithPrefix | FilePath, prefix?: string): Promise<DocumentID> {
|
|
return await this.services.path.path2id(filename, prefix);
|
|
}
|
|
|
|
getPath(entry: DocumentPathRef): FilePathWithPrefix {
|
|
return this.services.path.getPath(entry);
|
|
}
|
|
|
|
constructor(core: LiveSyncCore) {
|
|
this.core = core;
|
|
this.onBindFunction(this.core, this.core.services);
|
|
this._log = createInstanceLogFunction(this.constructor.name, this.services.API);
|
|
// __$checkInstanceBinding(this);
|
|
}
|
|
abstract onunload(): void | Promise<void>;
|
|
abstract onload(): void | Promise<void>;
|
|
|
|
_isMainReady() {
|
|
return this.services.appLifecycle.isReady();
|
|
}
|
|
_isMainSuspended() {
|
|
return this.services.appLifecycle.isSuspended();
|
|
}
|
|
_isDatabaseReady() {
|
|
return this.services.database.isDatabaseReady();
|
|
}
|
|
|
|
_log: ReturnType<typeof createInstanceLogFunction>;
|
|
|
|
_verbose = (msg: unknown, key?: string) => {
|
|
this._log(msg, LOG_LEVEL_VERBOSE, key);
|
|
};
|
|
|
|
_info = (msg: unknown, key?: string) => {
|
|
this._log(msg, LOG_LEVEL_INFO, key);
|
|
};
|
|
|
|
_notice = (msg: unknown, key?: string) => {
|
|
this._log(msg, LOG_LEVEL_NOTICE, key);
|
|
};
|
|
_progress = (prefix: string = "", level: LOG_LEVEL = LOG_LEVEL_NOTICE) => {
|
|
const key = `keepalive-progress-${noticeIndex++}`;
|
|
return {
|
|
log: (msg: string) => {
|
|
this._log(prefix + msg, level, key);
|
|
},
|
|
once: (msg: string) => {
|
|
this._log(prefix + msg, level);
|
|
},
|
|
done: (msg: string = "Done") => {
|
|
this._log(prefix + msg + MARK_DONE, level, key);
|
|
},
|
|
};
|
|
};
|
|
|
|
_debug = (msg: unknown, key?: string) => {
|
|
this._log(msg, LOG_LEVEL_VERBOSE, key);
|
|
};
|
|
|
|
onBindFunction(core: LiveSyncCore, services: typeof core.services) {
|
|
// Override if needed.
|
|
}
|
|
}
|