Extract library from plugin

This commit is contained in:
Andras Schmelczer 2025-02-18 22:32:41 +00:00
parent 8374c971ee
commit ae3acb9e1e
No known key found for this signature in database
GPG key ID: FC8F2C3D3D1A718C
37 changed files with 61 additions and 77 deletions

View file

@ -7,4 +7,4 @@
"author": "Andras Schmelczer",
"authorUrl": "https://schmelczer.dev",
"isDesktopOnly": false
}
}

View file

@ -13,6 +13,7 @@
"@types/node": "^16.11.6",
"builtin-modules": "3.3.0",
"byte-base64": "^1.1.0",
"client": "file:../client",
"css-loader": "^7.1.2",
"date-fns": "^4.1.0",
"dayjs": "^1.11.13",
@ -51,6 +52,11 @@
"dev": true,
"license": "MIT"
},
"../client": {
"name": "my-lib",
"version": "1.0.0",
"dev": true
},
"node_modules/@ampproject/remapping": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/@ampproject/remapping/-/remapping-2.3.0.tgz",
@ -3343,6 +3349,10 @@
"dev": true,
"license": "MIT"
},
"node_modules/client": {
"resolved": "../client",
"link": true
},
"node_modules/cliui": {
"version": "8.0.1",
"resolved": "https://registry.npmjs.org/cliui/-/cliui-8.0.1.tgz",

View file

@ -6,53 +6,32 @@
"scripts": {
"dev": "webpack watch --mode development",
"build": "webpack --mode production",
"test": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" jest",
"lint": "eslint --fix src && prettier --write \"src/**/*.(ts|scss|json|html)\"",
"test": "jest --passWithNoTests",
"version": "node version-bump.mjs"
},
"keywords": [],
"author": "",
"license": "MIT",
"prettier": {
"trailingComma": "none",
"tabWidth": 4,
"useTabs": true,
"endOfLine": "lf"
},
"devDependencies": {
"sync-client": "file:../sync-client",
"@types/jest": "^29.5.14",
"@types/node": "^16.11.6",
"builtin-modules": "3.3.0",
"byte-base64": "^1.1.0",
"css-loader": "^7.1.2",
"date-fns": "^4.1.0",
"dayjs": "^1.11.13",
"esbuild": "0.24.0",
"esbuild-plugin-wasm-pack": "^1.1.0",
"esbuild-sass-plugin": "^3.3.1",
"eslint": "9.17.0",
"eslint-plugin-unused-imports": "^4.1.4",
"fetch-retry": "^6.0.0",
"file-loader": "^6.2.0",
"fs-extra": "^11.2.0",
"virtual-scroller": "^1.13.1",
"jest": "^29.7.0",
"mini-css-extract-plugin": "^2.9.2",
"obsidian": "1.7.2",
"openapi-fetch": "0.13.3",
"openapi-typescript": "7.4.4",
"p-queue": "^8.0.1",
"prettier": "^3.4.2",
"resolve-url-loader": "^5.0.0",
"sass-loader": "^16.0.4",
"sync_lib": "file:../backend/sync_lib/pkg",
"terser-webpack-plugin": "^5.3.11",
"ts-jest": "^29.2.5",
"ts-loader": "^9.5.1",
"tslib": "2.4.0",
"typescript": "5.7.2",
"typescript-eslint": "8.18.0",
"webpack": "^5.97.1",
"webpack-cli": "^6.0.1"
}
}
}

View file

@ -1,10 +1,9 @@
import type { Syncer } from "sync-client";
import { Logger } from "sync-client";
import type { TAbstractFile } from "obsidian";
import { TFile } from "obsidian";
import type { FileEventHandler } from "./file-event-handler";
import { Logger } from "src/tracing/logger";
import type { Syncer } from "src/sync-operations/syncer";
export class ObsidianFileEventHandler implements FileEventHandler {
export class ObsidianFileEventHandler {
public constructor(private readonly syncer: Syncer) {}
public async onCreate(file: TAbstractFile): Promise<void> {

View file

@ -1,10 +1,8 @@
import type { Stat, Vault } from "obsidian";
import { normalizePath } from "obsidian";
import type { FileOperations } from "./file-operations";
import type { RelativePath } from "src/database/document-metadata";
import { isFileTypeMergable, mergeText } from "sync_lib";
import { Platform } from "obsidian";
import { Logger } from "src/tracing/logger";
import type { FileOperations, RelativePath } from "sync-client";
import { Logger, isFileTypeMergable, mergeText } from "sync-client";
export class ObsidianFileOperations implements FileOperations {
public constructor(private readonly vault: Vault) {}

View file

@ -2,21 +2,24 @@ import type { WorkspaceLeaf } from "obsidian";
import { Plugin } from "obsidian";
import "./styles.scss";
import "../manifest.json";
import init from "sync_lib";
import wasmBin from "sync_lib/sync_lib_bg.wasm";
import { SyncSettingsTab } from "./views/settings-tab";
import { HistoryView } from "./views/history-view";
import { ObsidianFileEventHandler } from "./events/obisidan-event-handler";
import { SyncService } from "./services/sync-service";
import { Database } from "./database/database";
import { applyRemoteChangesLocally } from "./sync-operations/apply-remote-changes-locally";
import { ObsidianFileOperations } from "./file-operations/obsidian-file-operations";
import { ObsidianFileEventHandler } from "./obisidan-event-handler";
import { ObsidianFileOperations } from "./obsidian-file-operations";
import { StatusBar } from "./views/status-bar";
import { Logger } from "./tracing/logger";
import { SyncHistory } from "./tracing/sync-history";
import { LogsView } from "./views/logs-view";
import { Syncer } from "./sync-operations/syncer";
import { StatusDescription } from "./views/status-description";
import {
applyRemoteChangesLocally,
Database,
Logger,
Syncer,
SyncHistory,
SyncService,
initialize
} from "sync-client";
export default class VaultLinkPlugin extends Plugin {
private readonly operations = new ObsidianFileOperations(this.app.vault);
@ -27,10 +30,7 @@ export default class VaultLinkPlugin extends Plugin {
public async onload(): Promise<void> {
Logger.getInstance().info("Starting plugin");
await init(
// eslint-disable-next-line
(wasmBin as any).default // it is loaded as a base64 string by webpack
);
await initialize();
const database = new Database(
await this.loadData(),

View file

@ -1,10 +1,14 @@
import type { IconName, WorkspaceLeaf } from "obsidian";
import { ItemView, setIcon } from "obsidian";
import type { HistoryEntry, SyncHistory } from "src/tracing/sync-history";
import { SyncType } from "src/tracing/sync-history";
import { SyncSource, SyncStatus } from "src/tracing/sync-history";
import { intlFormatDistance } from "date-fns";
import type { Database } from "src/database/database";
import type {
SyncHistory,
HistoryEntry,
Database,
RelativePath
} from "sync-client";
import { SyncType, SyncSource, SyncStatus } from "sync-client";
export class HistoryView extends ItemView {
public static readonly TYPE = "history-view";

View file

@ -1,8 +1,8 @@
import type { WorkspaceLeaf } from "obsidian";
import { ItemView } from "obsidian";
import type VaultLinkPlugin from "src/vault-link-plugin";
import { Logger } from "src/tracing/logger";
import type { Database } from "src/database/database";
import type { Database } from "sync-client";
import { Logger } from "sync-client";
export class LogsView extends ItemView {
public static readonly TYPE = "logs-view";

View file

@ -2,13 +2,11 @@ import type { App } from "obsidian";
import { Notice, PluginSettingTab, Setting } from "obsidian";
import type VaultLinkPlugin from "src/vault-link-plugin";
import type { Database } from "src/database/database";
import type { SyncService } from "src/services/sync-service";
import type { Syncer } from "src/sync-operations/syncer";
import type { StatusDescription } from "./status-description";
import { LogsView } from "./logs-view";
import { HistoryView } from "./history-view";
import { Logger, LogLevel } from "src/tracing/logger";
import type { SyncService, Syncer, Database } from "sync-client";
import { Logger, LogLevel } from "sync-client";
export class SyncSettingsTab extends PluginSettingTab {
private editedVaultName: string;

View file

@ -1,7 +1,5 @@
import type { Database } from "src/database/database";
import type { Database, HistoryStats, SyncHistory, Syncer } from "sync-client";
import type VaultLinkPlugin from "src/vault-link-plugin";
import type { Syncer } from "src/sync-operations/syncer";
import type { HistoryStats, SyncHistory } from "src/tracing/sync-history";
export class StatusBar {
private readonly statusBarItem: HTMLElement;

View file

@ -1,10 +1,11 @@
import type { Database } from "src/database/database";
import type {
HistoryStats,
CheckConnectionResult,
SyncService
} from "src/services/sync-service";
import type { Syncer } from "src/sync-operations/syncer";
import type { HistoryStats, SyncHistory } from "src/tracing/sync-history";
SyncService,
SyncHistory,
Syncer,
Database
} from "sync-client";
export class StatusDescription {
private lastHistoryStats: HistoryStats | undefined;

View file

@ -5,10 +5,8 @@
"inlineSources": true,
"module": "ESNext",
"target": "ES6",
"allowJs": true,
"noImplicitAny": true,
"moduleResolution": "bundler",
"importHelpers": true,
"isolatedModules": true,
"strictNullChecks": true,
"esModuleInterop": true,

View file

@ -1,8 +1,8 @@
import type { Client } from "openapi-fetch";
import createClient from "openapi-fetch";
import type { components, paths } from "./types"; // Generated by openapi-typescript
import type { Database } from "src/database/database";
import type { SyncSettings } from "src/database/sync-settings";
import type { Database } from "../database/database";
import type { SyncSettings } from "../database/sync-settings";
import type {
DocumentId,
RelativePath,
@ -98,9 +98,9 @@ export class SyncService {
}
Logger.getInstance().debug(
`Created document ${JSON.stringify(
response.data
)} with id ${response.data.documentId}`
`Created document ${JSON.stringify(response.data)} with id ${
response.data.documentId
}`
);
return response.data;
@ -149,7 +149,9 @@ export class SyncService {
}
Logger.getInstance().debug(
`Updated document ${JSON.stringify(response.data)} with id ${response.data.documentId}`
`Updated document ${JSON.stringify(response.data)} with id ${
response.data.documentId
}`
);
return response.data;

View file

@ -1,4 +1,4 @@
import type { Database } from "src/database/database";
import type { Database } from "../database/database";
import type { SyncService } from "src/services/sync-service";
import { Logger } from "src/tracing/logger";
import type { Syncer } from "./syncer";

View file

@ -1,5 +1,3 @@
import { Notice } from "obsidian";
export enum LogLevel {
DEBUG = "DEBUG",
INFO = "INFO",
@ -62,7 +60,6 @@ export class Logger {
console.error(message);
this.pushMessage(message, LogLevel.ERROR);
new Notice(message, 5000);
}
public getMessages(mininumSeverity: LogLevel): LogLine[] {