mirror of
https://github.com/vrtmrz/obsidian-livesync.git
synced 2026-04-05 08:35:19 +00:00
chore(format): no intentional behaviour change - runs pretty
This commit is contained in:
@@ -3,8 +3,14 @@ import type { LOG_LEVEL } from "../lib/src/common/types";
|
||||
import type { LiveSyncCore } from "../main";
|
||||
import { unique } from "octagonal-wheels/collection";
|
||||
import type { IObsidianModule } from "./AbstractObsidianModule.ts";
|
||||
import type { ICoreModuleBase, AllInjectableProps, AllExecuteProps, EveryExecuteProps, AnyExecuteProps, ICoreModule } from "./ModuleTypes";
|
||||
|
||||
import type {
|
||||
ICoreModuleBase,
|
||||
AllInjectableProps,
|
||||
AllExecuteProps,
|
||||
EveryExecuteProps,
|
||||
AnyExecuteProps,
|
||||
ICoreModule,
|
||||
} from "./ModuleTypes";
|
||||
|
||||
function isOverridableKey(key: string): key is keyof ICoreModuleBase {
|
||||
return key.startsWith("$");
|
||||
@@ -14,7 +20,6 @@ function isInjectableKey(key: string): key is keyof AllInjectableProps {
|
||||
return key.startsWith("$$");
|
||||
}
|
||||
|
||||
|
||||
function isAllExecuteKey(key: string): key is keyof AllExecuteProps {
|
||||
return key.startsWith("$all");
|
||||
}
|
||||
@@ -35,15 +40,17 @@ function isAnyExecuteKey(key: string): key is keyof AnyExecuteProps {
|
||||
* All of above performed on injectModules function.
|
||||
*/
|
||||
export function injectModules<T extends ICoreModule>(target: T, modules: ICoreModule[]) {
|
||||
const allKeys = unique([...Object.keys(Object.getOwnPropertyDescriptors(target)),
|
||||
...Object.keys(Object.getOwnPropertyDescriptors(Object.getPrototypeOf(target)))]).filter(e => e.startsWith("$")) as (keyof ICoreModule)[];
|
||||
const allKeys = unique([
|
||||
...Object.keys(Object.getOwnPropertyDescriptors(target)),
|
||||
...Object.keys(Object.getOwnPropertyDescriptors(Object.getPrototypeOf(target))),
|
||||
]).filter((e) => e.startsWith("$")) as (keyof ICoreModule)[];
|
||||
const moduleMap = new Map<string, IObsidianModule[]>();
|
||||
for (const module of modules) {
|
||||
for (const key of allKeys) {
|
||||
if (isOverridableKey(key)) {
|
||||
if (key in module) {
|
||||
const list = moduleMap.get(key) || [];
|
||||
if (typeof module[key] === 'function') {
|
||||
if (typeof module[key] === "function") {
|
||||
module[key] = module[key].bind(module) as any;
|
||||
}
|
||||
list.push(module);
|
||||
@@ -74,7 +81,7 @@ export function injectModules<T extends ICoreModule>(target: T, modules: ICoreMo
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
for (const module of modules) {
|
||||
Logger(`[${module.constructor.name}]: Injected (All) ${key} `, LOG_LEVEL_VERBOSE);
|
||||
}
|
||||
@@ -94,7 +101,7 @@ export function injectModules<T extends ICoreModule>(target: T, modules: ICoreMo
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
for (const module of modules) {
|
||||
Logger(`[${module.constructor.name}]: Injected (Every) ${key} `, LOG_LEVEL_VERBOSE);
|
||||
}
|
||||
@@ -115,7 +122,7 @@ export function injectModules<T extends ICoreModule>(target: T, modules: ICoreMo
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
for (const module of modules) {
|
||||
Logger(`[${module.constructor.name}]: Injected (Any) ${key} `, LOG_LEVEL_VERBOSE);
|
||||
}
|
||||
@@ -127,7 +134,6 @@ export function injectModules<T extends ICoreModule>(target: T, modules: ICoreMo
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
export abstract class AbstractModule {
|
||||
_log = (msg: any, level: LOG_LEVEL = LOG_LEVEL_INFO, key?: string) => {
|
||||
if (typeof msg === "string" && level !== LOG_LEVEL_NOTICE) {
|
||||
@@ -173,11 +179,10 @@ export abstract class AbstractModule {
|
||||
return this.testFail(`${key} failed: ${ret}`);
|
||||
}
|
||||
this.addTestResult(key, true, "");
|
||||
}
|
||||
catch (ex: any) {
|
||||
} catch (ex: any) {
|
||||
this.addTestResult(key, false, "Failed by Exception", ex.toString());
|
||||
return this.testFail(`${key} failed: ${ex}`);
|
||||
}
|
||||
return this.testDone();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user