From 2ae018b2bdbffb4f45d9347c3cc22b7365758fab Mon Sep 17 00:00:00 2001 From: vorotamoroz Date: Thu, 2 May 2024 04:07:36 +0100 Subject: [PATCH] Refactor: - Files have been categorised for clarity. The deliverables are not affected. --- src/{ => common}/KeyValueDB.ts | 0 src/{ => common}/ObsHttpHandler.ts | 2 +- src/{ => common}/dialogs.ts | 6 +- src/{ => common}/stores.ts | 2 +- src/{ => common}/types.ts | 4 +- src/{ => common}/utils.ts | 22 +++--- src/deps.ts | 2 +- src/{ => features}/CmdConfigSync.ts | 32 ++++---- src/{ => features}/CmdHiddenFileSync.ts | 26 +++---- src/{ => features}/CmdSetupLiveSync.ts | 24 +++--- src/{ => features}/LiveSyncCommands.ts | 6 +- src/lib | 2 +- src/main.ts | 74 +++++++++---------- src/{ => storages}/SerializedFileAccess.ts | 16 ++-- src/{ => storages}/StorageEventManager.ts | 16 ++-- src/{ => ui}/ConflictResolveModal.ts | 8 +- src/{ => ui}/DocumentHistoryModal.ts | 18 ++--- src/{ => ui}/GlobalHistory.svelte | 12 +-- src/{ => ui}/GlobalHistoryView.ts | 4 +- src/{ => ui}/JsonResolveModal.ts | 6 +- src/{ => ui}/JsonResolvePane.svelte | 10 +-- src/{ => ui}/LogDisplayModal.ts | 10 +-- src/{ => ui}/LogPane.svelte | 6 +- src/{ => ui}/LogPaneView.ts | 2 +- src/{ => ui}/ObsidianLiveSyncSettingTab.ts | 24 +++--- src/{ => ui}/PluginPane.svelte | 12 +-- .../components}/MultipleRegExpControl.svelte | 0 src/{ => ui/components}/PluginCombo.svelte | 14 ++-- 28 files changed, 180 insertions(+), 180 deletions(-) rename src/{ => common}/KeyValueDB.ts (100%) rename src/{ => common}/ObsHttpHandler.ts (98%) rename src/{ => common}/dialogs.ts (98%) rename src/{ => common}/stores.ts (73%) rename src/{ => common}/types.ts (95%) rename src/{ => common}/utils.ts (96%) rename src/{ => features}/CmdConfigSync.ts (97%) rename src/{ => features}/CmdHiddenFileSync.ts (97%) rename src/{ => features}/CmdSetupLiveSync.ts (96%) rename src/{ => features}/LiveSyncCommands.ts (86%) rename src/{ => storages}/SerializedFileAccess.ts (94%) rename src/{ => storages}/StorageEventManager.ts (93%) rename src/{ => ui}/ConflictResolveModal.ts (94%) rename src/{ => ui}/DocumentHistoryModal.ts (95%) rename src/{ => ui}/GlobalHistory.svelte (97%) rename src/{ => ui}/GlobalHistoryView.ts (93%) rename src/{ => ui}/JsonResolveModal.ts (91%) rename src/{ => ui}/JsonResolvePane.svelte (94%) rename src/{ => ui}/LogDisplayModal.ts (77%) rename src/{ => ui}/LogPane.svelte (91%) rename src/{ => ui}/LogPaneView.ts (94%) rename src/{ => ui}/ObsidianLiveSyncSettingTab.ts (99%) rename src/{ => ui}/PluginPane.svelte (98%) rename src/{ => ui/components}/MultipleRegExpControl.svelte (100%) rename src/{ => ui/components}/PluginCombo.svelte (95%) diff --git a/src/KeyValueDB.ts b/src/common/KeyValueDB.ts similarity index 100% rename from src/KeyValueDB.ts rename to src/common/KeyValueDB.ts diff --git a/src/ObsHttpHandler.ts b/src/common/ObsHttpHandler.ts similarity index 98% rename from src/ObsHttpHandler.ts rename to src/common/ObsHttpHandler.ts index 1f74298..a7bef97 100644 --- a/src/ObsHttpHandler.ts +++ b/src/common/ObsHttpHandler.ts @@ -11,7 +11,7 @@ import { HttpRequest, HttpResponse, type HttpHandlerOptions } from "@smithy/prot //@ts-ignore import { requestTimeout } from "@smithy/fetch-http-handler/dist-es/request-timeout"; import { buildQueryString } from "@smithy/querystring-builder"; -import { requestUrl, type RequestUrlParam } from "./deps"; +import { requestUrl, type RequestUrlParam } from "../deps.ts"; //////////////////////////////////////////////////////////////////////////////// // special handler using Obsidian requestUrl //////////////////////////////////////////////////////////////////////////////// diff --git a/src/dialogs.ts b/src/common/dialogs.ts similarity index 98% rename from src/dialogs.ts rename to src/common/dialogs.ts index ddc1eab..836da90 100644 --- a/src/dialogs.ts +++ b/src/common/dialogs.ts @@ -1,9 +1,9 @@ import { ButtonComponent } from "obsidian"; -import { App, FuzzySuggestModal, MarkdownRenderer, Modal, Plugin, Setting } from "./deps"; -import ObsidianLiveSyncPlugin from "./main"; +import { App, FuzzySuggestModal, MarkdownRenderer, Modal, Plugin, Setting } from "../deps.ts"; +import ObsidianLiveSyncPlugin from "../main.ts"; //@ts-ignore -import PluginPane from "./PluginPane.svelte"; +import PluginPane from "../ui/PluginPane.svelte"; export class PluginDialogModal extends Modal { plugin: ObsidianLiveSyncPlugin; diff --git a/src/stores.ts b/src/common/stores.ts similarity index 73% rename from src/stores.ts rename to src/common/stores.ts index 85e0421..80627c4 100644 --- a/src/stores.ts +++ b/src/common/stores.ts @@ -1,4 +1,4 @@ -import { PersistentMap } from "./lib/src/PersistentMap"; +import { PersistentMap } from "../lib/src/dataobject/PersistentMap.ts"; export let sameChangePairs: PersistentMap; diff --git a/src/types.ts b/src/common/types.ts similarity index 95% rename from src/types.ts rename to src/common/types.ts index 99433b6..221e8d5 100644 --- a/src/types.ts +++ b/src/common/types.ts @@ -1,5 +1,5 @@ -import { type PluginManifest, TFile } from "./deps"; -import { type DatabaseEntry, type EntryBody, type FilePath } from "./lib/src/types"; +import { type PluginManifest, TFile } from "../deps.ts"; +import { type DatabaseEntry, type EntryBody, type FilePath } from "../lib/src/common/types.ts"; export interface PluginDataEntry extends DatabaseEntry { deviceVaultName: string; diff --git a/src/utils.ts b/src/common/utils.ts similarity index 96% rename from src/utils.ts rename to src/common/utils.ts index bed6da7..2bc8c85 100644 --- a/src/utils.ts +++ b/src/common/utils.ts @@ -1,16 +1,16 @@ -import { normalizePath, Platform, TAbstractFile, App, type RequestUrlParam, requestUrl, TFile } from "./deps"; -import { path2id_base, id2path_base, isValidFilenameInLinux, isValidFilenameInDarwin, isValidFilenameInWidows, isValidFilenameInAndroid, stripAllPrefixes } from "./lib/src/path"; +import { normalizePath, Platform, TAbstractFile, App, type RequestUrlParam, requestUrl, TFile } from "../deps.ts"; +import { path2id_base, id2path_base, isValidFilenameInLinux, isValidFilenameInDarwin, isValidFilenameInWidows, isValidFilenameInAndroid, stripAllPrefixes } from "../lib/src/string_and_binary/path.ts"; -import { Logger } from "./lib/src/logger"; -import { LOG_LEVEL_VERBOSE, type AnyEntry, type DocumentID, type EntryHasPath, type FilePath, type FilePathWithPrefix } from "./lib/src/types"; -import { CHeader, ICHeader, ICHeaderLength, ICXHeader, PSCHeader } from "./types"; -import { InputStringDialog, PopoverSelectString } from "./dialogs"; -import type ObsidianLiveSyncPlugin from "./main"; -import { writeString } from "./lib/src/strbin"; -import { fireAndForget } from "./lib/src/utils"; -import { sameChangePairs } from "./stores"; +import { Logger } from "../lib/src/common/logger.ts"; +import { LOG_LEVEL_VERBOSE, type AnyEntry, type DocumentID, type EntryHasPath, type FilePath, type FilePathWithPrefix } from "../lib/src/common/types.ts"; +import { CHeader, ICHeader, ICHeaderLength, ICXHeader, PSCHeader } from "./types.ts"; +import { InputStringDialog, PopoverSelectString } from "./dialogs.ts"; +import type ObsidianLiveSyncPlugin from "../main.ts"; +import { writeString } from "../lib/src/string_and_binary/strbin.ts"; +import { fireAndForget } from "../lib/src/common/utils.ts"; +import { sameChangePairs } from "./stores.ts"; -export { scheduleTask, setPeriodicTask, cancelTask, cancelAllTasks, cancelPeriodicTask, cancelAllPeriodicTask, } from "./lib/src/task"; +export { scheduleTask, setPeriodicTask, cancelTask, cancelAllTasks, cancelPeriodicTask, cancelAllPeriodicTask, } from "../lib/src/concurrency/task.ts"; // For backward compatibility, using the path for determining id. // Only CouchDB unacceptable ID (that starts with an underscore) has been prefixed with "/". diff --git a/src/deps.ts b/src/deps.ts index a21480e..159e505 100644 --- a/src/deps.ts +++ b/src/deps.ts @@ -1,4 +1,4 @@ -import { type FilePath } from "./lib/src/types"; +import { type FilePath } from "./lib/src/common/types.ts"; export { addIcon, App, debounce, Editor, FuzzySuggestModal, MarkdownRenderer, MarkdownView, Modal, Notice, Platform, Plugin, PluginSettingTab, requestUrl, sanitizeHTMLToDom, Setting, stringifyYaml, TAbstractFile, TextAreaComponent, TFile, TFolder, diff --git a/src/CmdConfigSync.ts b/src/features/CmdConfigSync.ts similarity index 97% rename from src/CmdConfigSync.ts rename to src/features/CmdConfigSync.ts index eb7d1b5..201ade6 100644 --- a/src/CmdConfigSync.ts +++ b/src/features/CmdConfigSync.ts @@ -1,21 +1,21 @@ import { writable } from 'svelte/store'; -import { Notice, type PluginManifest, parseYaml, normalizePath, type ListedFiles } from "./deps"; +import { Notice, type PluginManifest, parseYaml, normalizePath, type ListedFiles } from "../deps.ts"; -import type { EntryDoc, LoadedEntry, InternalFileEntry, FilePathWithPrefix, FilePath, DocumentID, AnyEntry, SavingEntry } from "./lib/src/types"; -import { LOG_LEVEL_INFO, LOG_LEVEL_NOTICE, LOG_LEVEL_VERBOSE, MODE_SELECTIVE } from "./lib/src/types"; -import { ICXHeader, PERIODIC_PLUGIN_SWEEP, } from "./types"; -import { createSavingEntryFromLoadedEntry, createTextBlob, delay, fireAndForget, getDocData, isDocContentSame, throttle } from "./lib/src/utils"; -import { Logger } from "./lib/src/logger"; -import { readString, decodeBinary, arrayBufferToBase64, digestHash } from "./lib/src/strbin"; -import { serialized } from "./lib/src/lock"; -import { LiveSyncCommands } from "./LiveSyncCommands"; -import { stripAllPrefixes } from "./lib/src/path"; -import { PeriodicProcessor, askYesNo, disposeMemoObject, memoIfNotExist, memoObject, retrieveMemoObject, scheduleTask } from "./utils"; -import { PluginDialogModal } from "./dialogs"; -import { JsonResolveModal } from "./JsonResolveModal"; -import { QueueProcessor } from './lib/src/processor'; -import { pluginScanningCount } from './lib/src/stores'; -import type ObsidianLiveSyncPlugin from './main'; +import type { EntryDoc, LoadedEntry, InternalFileEntry, FilePathWithPrefix, FilePath, DocumentID, AnyEntry, SavingEntry } from "../lib/src/common/types.ts"; +import { LOG_LEVEL_INFO, LOG_LEVEL_NOTICE, LOG_LEVEL_VERBOSE, MODE_SELECTIVE } from "../lib/src/common/types.ts"; +import { ICXHeader, PERIODIC_PLUGIN_SWEEP, } from "../common/types.ts"; +import { createSavingEntryFromLoadedEntry, createTextBlob, delay, fireAndForget, getDocData, isDocContentSame, throttle } from "../lib/src/common/utils.ts"; +import { Logger } from "../lib/src/common/logger.ts"; +import { readString, decodeBinary, arrayBufferToBase64, digestHash } from "../lib/src/string_and_binary/strbin.ts"; +import { serialized } from "../lib/src/concurrency/lock.ts"; +import { LiveSyncCommands } from "./LiveSyncCommands.ts"; +import { stripAllPrefixes } from "../lib/src/string_and_binary/path.ts"; +import { PeriodicProcessor, askYesNo, disposeMemoObject, memoIfNotExist, memoObject, retrieveMemoObject, scheduleTask } from "../common/utils.ts"; +import { PluginDialogModal } from "../common/dialogs.ts"; +import { JsonResolveModal } from "../ui/JsonResolveModal.ts"; +import { QueueProcessor } from '../lib/src/concurrency/processor.ts'; +import { pluginScanningCount } from '../lib/src/mock_and_interop/stores.ts'; +import type ObsidianLiveSyncPlugin from '../main.ts'; const d = "\u200b"; const d2 = "\n"; diff --git a/src/CmdHiddenFileSync.ts b/src/features/CmdHiddenFileSync.ts similarity index 97% rename from src/CmdHiddenFileSync.ts rename to src/features/CmdHiddenFileSync.ts index 0f05519..9476df2 100644 --- a/src/CmdHiddenFileSync.ts +++ b/src/features/CmdHiddenFileSync.ts @@ -1,16 +1,16 @@ -import { normalizePath, type PluginManifest, type ListedFiles } from "./deps"; -import { type EntryDoc, type LoadedEntry, type InternalFileEntry, type FilePathWithPrefix, type FilePath, LOG_LEVEL_INFO, LOG_LEVEL_NOTICE, LOG_LEVEL_VERBOSE, MODE_SELECTIVE, MODE_PAUSED, type SavingEntry, type DocumentID } from "./lib/src/types"; -import { type InternalFileInfo, ICHeader, ICHeaderEnd } from "./types"; -import { readAsBlob, isDocContentSame, sendSignal, readContent, createBlob } from "./lib/src/utils"; -import { Logger } from "./lib/src/logger"; -import { PouchDB } from "./lib/src/pouchdb-browser.js"; -import { isInternalMetadata, PeriodicProcessor } from "./utils"; -import { serialized } from "./lib/src/lock"; -import { JsonResolveModal } from "./JsonResolveModal"; -import { LiveSyncCommands } from "./LiveSyncCommands"; -import { addPrefix, stripAllPrefixes } from "./lib/src/path"; -import { QueueProcessor } from "./lib/src/processor"; -import { hiddenFilesEventCount, hiddenFilesProcessingCount } from "./lib/src/stores"; +import { normalizePath, type PluginManifest, type ListedFiles } from "../deps.ts"; +import { type EntryDoc, type LoadedEntry, type InternalFileEntry, type FilePathWithPrefix, type FilePath, LOG_LEVEL_INFO, LOG_LEVEL_NOTICE, LOG_LEVEL_VERBOSE, MODE_SELECTIVE, MODE_PAUSED, type SavingEntry, type DocumentID } from "../lib/src/common/types.ts"; +import { type InternalFileInfo, ICHeader, ICHeaderEnd } from "../common/types.ts"; +import { readAsBlob, isDocContentSame, sendSignal, readContent, createBlob } from "../lib/src/common/utils.ts"; +import { Logger } from "../lib/src/common/logger.ts"; +import { PouchDB } from "../lib/src/pouchdb/pouchdb-browser.js"; +import { isInternalMetadata, PeriodicProcessor } from "../common/utils.ts"; +import { serialized } from "../lib/src/concurrency/lock.ts"; +import { JsonResolveModal } from "../ui/JsonResolveModal.ts"; +import { LiveSyncCommands } from "./LiveSyncCommands.ts"; +import { addPrefix, stripAllPrefixes } from "../lib/src/string_and_binary/path.ts"; +import { QueueProcessor } from "../lib/src/concurrency/processor.ts"; +import { hiddenFilesEventCount, hiddenFilesProcessingCount } from "../lib/src/mock_and_interop/stores.ts"; export class HiddenFileSync extends LiveSyncCommands { periodicInternalFileScanProcessor: PeriodicProcessor = new PeriodicProcessor(this.plugin, async () => this.settings.syncInternalFiles && this.localDatabase.isReady && await this.syncInternalFilesAndDatabase("push", false)); diff --git a/src/CmdSetupLiveSync.ts b/src/features/CmdSetupLiveSync.ts similarity index 96% rename from src/CmdSetupLiveSync.ts rename to src/features/CmdSetupLiveSync.ts index 354d48b..28ee615 100644 --- a/src/CmdSetupLiveSync.ts +++ b/src/features/CmdSetupLiveSync.ts @@ -1,15 +1,15 @@ -import { type EntryDoc, type ObsidianLiveSyncSettings, DEFAULT_SETTINGS, LOG_LEVEL_NOTICE, REMOTE_COUCHDB, REMOTE_MINIO } from "./lib/src/types"; -import { configURIBase } from "./types"; -import { Logger } from "./lib/src/logger"; -import { PouchDB } from "./lib/src/pouchdb-browser.js"; -import { askSelectString, askYesNo, askString } from "./utils"; -import { decrypt, encrypt } from "./lib/src/e2ee_v2"; -import { LiveSyncCommands } from "./LiveSyncCommands"; -import { delay, fireAndForget } from "./lib/src/utils"; -import { confirmWithMessage } from "./dialogs"; -import { Platform } from "./deps"; -import { fetchAllUsedChunks } from "./lib/src/utils_couchdb"; -import type { LiveSyncCouchDBReplicator } from "./lib/src/LiveSyncReplicator.js"; +import { type EntryDoc, type ObsidianLiveSyncSettings, DEFAULT_SETTINGS, LOG_LEVEL_NOTICE, REMOTE_COUCHDB, REMOTE_MINIO } from "../lib/src/common/types.ts"; +import { configURIBase } from "../common/types.ts"; +import { Logger } from "../lib/src/common/logger.ts"; +import { PouchDB } from "../lib/src/pouchdb/pouchdb-browser.js"; +import { askSelectString, askYesNo, askString } from "../common/utils.ts"; +import { decrypt, encrypt } from "../lib/src/encryption/e2ee_v2.ts"; +import { LiveSyncCommands } from "./LiveSyncCommands.ts"; +import { delay, fireAndForget } from "../lib/src/common/utils.ts"; +import { confirmWithMessage } from "../common/dialogs.ts"; +import { Platform } from "../deps.ts"; +import { fetchAllUsedChunks } from "../lib/src/pouchdb/utils_couchdb.ts"; +import type { LiveSyncCouchDBReplicator } from "../lib/src/replication/couchdb/LiveSyncReplicator.js"; export class SetupLiveSync extends LiveSyncCommands { onunload() { } diff --git a/src/LiveSyncCommands.ts b/src/features/LiveSyncCommands.ts similarity index 86% rename from src/LiveSyncCommands.ts rename to src/features/LiveSyncCommands.ts index 99eb7fa..b4eb807 100644 --- a/src/LiveSyncCommands.ts +++ b/src/features/LiveSyncCommands.ts @@ -1,6 +1,6 @@ -import { type AnyEntry, type DocumentID, type EntryDoc, type EntryHasPath, type FilePath, type FilePathWithPrefix } from "./lib/src/types"; -import { PouchDB } from "./lib/src/pouchdb-browser.js"; -import type ObsidianLiveSyncPlugin from "./main"; +import { type AnyEntry, type DocumentID, type EntryDoc, type EntryHasPath, type FilePath, type FilePathWithPrefix } from "../lib/src/common/types.ts"; +import { PouchDB } from "../lib/src/pouchdb/pouchdb-browser.js"; +import type ObsidianLiveSyncPlugin from "../main.ts"; export abstract class LiveSyncCommands { diff --git a/src/lib b/src/lib index 60d012f..4dfdcbe 160000 --- a/src/lib +++ b/src/lib @@ -1 +1 @@ -Subproject commit 60d012f92d87407b83379c676b8838e36b1ba16a +Subproject commit 4dfdcbe2ea6004f74a36058bd4533c3eaaf524bc diff --git a/src/main.ts b/src/main.ts index 806cf5b..9dbc7ee 100644 --- a/src/main.ts +++ b/src/main.ts @@ -2,43 +2,43 @@ const isDebug = false; import { type Diff, DIFF_DELETE, DIFF_EQUAL, DIFF_INSERT, diff_match_patch, stringifyYaml, parseYaml } from "./deps"; import { Notice, Plugin, TFile, addIcon, TFolder, normalizePath, TAbstractFile, Editor, MarkdownView, type RequestUrlParam, type RequestUrlResponse, requestUrl, type MarkdownFileInfo } from "./deps"; -import { type EntryDoc, type LoadedEntry, type ObsidianLiveSyncSettings, type diff_check_result, type diff_result_leaf, type EntryBody, LOG_LEVEL, VER, DEFAULT_SETTINGS, type diff_result, FLAGMD_REDFLAG, SYNCINFO_ID, SALT_OF_PASSPHRASE, type ConfigPassphraseStore, type CouchDBConnection, FLAGMD_REDFLAG2, FLAGMD_REDFLAG3, PREFIXMD_LOGFILE, type DatabaseConnectingStatus, type EntryHasPath, type DocumentID, type FilePathWithPrefix, type FilePath, type AnyEntry, LOG_LEVEL_DEBUG, LOG_LEVEL_INFO, LOG_LEVEL_NOTICE, LOG_LEVEL_URGENT, LOG_LEVEL_VERBOSE, type SavingEntry, MISSING_OR_ERROR, NOT_CONFLICTED, AUTO_MERGED, CANCELLED, LEAVE_TO_SUBSEQUENT, FLAGMD_REDFLAG2_HR, FLAGMD_REDFLAG3_HR, REMOTE_MINIO, REMOTE_COUCHDB, type BucketSyncSetting, } from "./lib/src/types"; -import { type InternalFileInfo, type CacheData, type FileEventItem, FileWatchEventQueueMax } from "./types"; -import { arrayToChunkedArray, createBlob, delay, determineTypeFromBlob, fireAndForget, getDocData, isAnyNote, isDocContentSame, isObjectDifferent, readContent, sendValue, throttle, type SimpleStore } from "./lib/src/utils"; -import { Logger, setGlobalLogFunction } from "./lib/src/logger"; -import { PouchDB } from "./lib/src/pouchdb-browser.js"; -import { ConflictResolveModal } from "./ConflictResolveModal"; -import { ObsidianLiveSyncSettingTab } from "./ObsidianLiveSyncSettingTab"; -import { DocumentHistoryModal } from "./DocumentHistoryModal"; -import { applyPatch, cancelAllPeriodicTask, cancelAllTasks, cancelTask, generatePatchObj, id2path, isObjectMargeApplicable, isSensibleMargeApplicable, flattenObject, path2id, scheduleTask, tryParseJSON, isValidPath, isInternalMetadata, isPluginMetadata, stripInternalMetadataPrefix, isChunk, askSelectString, askYesNo, askString, PeriodicProcessor, getPath, getPathWithoutPrefix, getPathFromTFile, performRebuildDB, memoIfNotExist, memoObject, retrieveMemoObject, disposeMemoObject, isCustomisationSyncMetadata, compareFileFreshness, BASE_IS_NEW, TARGET_IS_NEW, EVEN, compareMTime, markChangesAreSame } from "./utils"; -import { encrypt, tryDecrypt } from "./lib/src/e2ee_v2"; -import { balanceChunkPurgedDBs, enableCompression, enableEncryption, isCloudantURI, isErrorOfMissingDoc, isValidRemoteCouchDBURI, purgeUnreferencedChunks } from "./lib/src/utils_couchdb"; -import { logStore, type LogEntry, collectingChunks, pluginScanningCount, hiddenFilesProcessingCount, hiddenFilesEventCount, logMessages } from "./lib/src/stores"; -import { setNoticeClass } from "./lib/src/wrapper"; -import { versionNumberString2Number, writeString, decodeBinary, readString } from "./lib/src/strbin"; -import { addPrefix, isAcceptedAll, isPlainText, shouldBeIgnored, stripAllPrefixes } from "./lib/src/path"; -import { isLockAcquired, serialized, shareRunningResult, skipIfDuplicated } from "./lib/src/lock"; -import { StorageEventManager, StorageEventManagerObsidian } from "./StorageEventManager"; -import { LiveSyncLocalDB, type LiveSyncLocalDBEnv } from "./lib/src/LiveSyncLocalDB"; -import { LiveSyncAbstractReplicator, type LiveSyncReplicatorEnv } from "./lib/src/LiveSyncAbstractReplicator.js"; -import { type KeyValueDatabase, OpenKeyValueDatabase } from "./KeyValueDB"; -import { LiveSyncCommands } from "./LiveSyncCommands"; -import { HiddenFileSync } from "./CmdHiddenFileSync"; -import { SetupLiveSync } from "./CmdSetupLiveSync"; -import { ConfigSync } from "./CmdConfigSync"; -import { confirmWithMessage } from "./dialogs"; -import { GlobalHistoryView, VIEW_TYPE_GLOBAL_HISTORY } from "./GlobalHistoryView"; -import { LogPaneView, VIEW_TYPE_LOG } from "./LogPaneView"; -import { LRUCache } from "./lib/src/LRUCache"; -import { SerializedFileAccess } from "./SerializedFileAccess.js"; -import { QueueProcessor } from "./lib/src/processor.js"; -import { reactive, reactiveSource } from "./lib/src/reactive.js"; -import { initializeStores } from "./stores.js"; -import { JournalSyncMinio } from "./lib/src/JournalSyncMinio.js"; -import { LiveSyncJournalReplicator, type LiveSyncJournalReplicatorEnv } from "./lib/src/LiveSyncJournalReplicator.js"; -import { LiveSyncCouchDBReplicator, type LiveSyncCouchDBReplicatorEnv } from "./lib/src/LiveSyncReplicator.js"; -import type { CheckPointInfo } from "./lib/src/JournalSyncTypes.js"; -import { ObsHttpHandler } from "./ObsHttpHandler.js"; +import { type EntryDoc, type LoadedEntry, type ObsidianLiveSyncSettings, type diff_check_result, type diff_result_leaf, type EntryBody, LOG_LEVEL, VER, DEFAULT_SETTINGS, type diff_result, FLAGMD_REDFLAG, SYNCINFO_ID, SALT_OF_PASSPHRASE, type ConfigPassphraseStore, type CouchDBConnection, FLAGMD_REDFLAG2, FLAGMD_REDFLAG3, PREFIXMD_LOGFILE, type DatabaseConnectingStatus, type EntryHasPath, type DocumentID, type FilePathWithPrefix, type FilePath, type AnyEntry, LOG_LEVEL_DEBUG, LOG_LEVEL_INFO, LOG_LEVEL_NOTICE, LOG_LEVEL_URGENT, LOG_LEVEL_VERBOSE, type SavingEntry, MISSING_OR_ERROR, NOT_CONFLICTED, AUTO_MERGED, CANCELLED, LEAVE_TO_SUBSEQUENT, FLAGMD_REDFLAG2_HR, FLAGMD_REDFLAG3_HR, REMOTE_MINIO, REMOTE_COUCHDB, type BucketSyncSetting, } from "./lib/src/common/types.ts"; +import { type InternalFileInfo, type CacheData, type FileEventItem, FileWatchEventQueueMax } from "./common/types.ts"; +import { arrayToChunkedArray, createBlob, delay, determineTypeFromBlob, fireAndForget, getDocData, isAnyNote, isDocContentSame, isObjectDifferent, readContent, sendValue, throttle, type SimpleStore } from "./lib/src/common/utils.ts"; +import { Logger, setGlobalLogFunction } from "./lib/src/common/logger.ts"; +import { PouchDB } from "./lib/src/pouchdb/pouchdb-browser.js"; +import { ConflictResolveModal } from "./ui/ConflictResolveModal.ts"; +import { ObsidianLiveSyncSettingTab } from "./ui/ObsidianLiveSyncSettingTab.ts"; +import { DocumentHistoryModal } from "./ui/DocumentHistoryModal.ts"; +import { applyPatch, cancelAllPeriodicTask, cancelAllTasks, cancelTask, generatePatchObj, id2path, isObjectMargeApplicable, isSensibleMargeApplicable, flattenObject, path2id, scheduleTask, tryParseJSON, isValidPath, isInternalMetadata, isPluginMetadata, stripInternalMetadataPrefix, isChunk, askSelectString, askYesNo, askString, PeriodicProcessor, getPath, getPathWithoutPrefix, getPathFromTFile, performRebuildDB, memoIfNotExist, memoObject, retrieveMemoObject, disposeMemoObject, isCustomisationSyncMetadata, compareFileFreshness, BASE_IS_NEW, TARGET_IS_NEW, EVEN, compareMTime, markChangesAreSame } from "./common/utils.ts"; +import { encrypt, tryDecrypt } from "./lib/src/encryption/e2ee_v2.ts"; +import { balanceChunkPurgedDBs, enableCompression, enableEncryption, isCloudantURI, isErrorOfMissingDoc, isValidRemoteCouchDBURI, purgeUnreferencedChunks } from "./lib/src/pouchdb/utils_couchdb.ts"; +import { logStore, type LogEntry, collectingChunks, pluginScanningCount, hiddenFilesProcessingCount, hiddenFilesEventCount, logMessages } from "./lib/src/mock_and_interop/stores.ts"; +import { setNoticeClass } from "./lib/src/mock_and_interop/wrapper.ts"; +import { versionNumberString2Number, writeString, decodeBinary, readString } from "./lib/src/string_and_binary/strbin.ts"; +import { addPrefix, isAcceptedAll, isPlainText, shouldBeIgnored, stripAllPrefixes } from "./lib/src/string_and_binary/path.ts"; +import { isLockAcquired, serialized, shareRunningResult, skipIfDuplicated } from "./lib/src/concurrency/lock.ts"; +import { StorageEventManager, StorageEventManagerObsidian } from "./storages/StorageEventManager.ts"; +import { LiveSyncLocalDB, type LiveSyncLocalDBEnv } from "./lib/src/pouchdb/LiveSyncLocalDB.ts"; +import { LiveSyncAbstractReplicator, type LiveSyncReplicatorEnv } from "./lib/src/replication/LiveSyncAbstractReplicator.js"; +import { type KeyValueDatabase, OpenKeyValueDatabase } from "./common/KeyValueDB.ts"; +import { LiveSyncCommands } from "./features/LiveSyncCommands.ts"; +import { HiddenFileSync } from "./features/CmdHiddenFileSync.ts"; +import { SetupLiveSync } from "./features/CmdSetupLiveSync.ts"; +import { ConfigSync } from "./features/CmdConfigSync.ts"; +import { confirmWithMessage } from "./common/dialogs.ts"; +import { GlobalHistoryView, VIEW_TYPE_GLOBAL_HISTORY } from "./ui/GlobalHistoryView.ts"; +import { LogPaneView, VIEW_TYPE_LOG } from "./ui/LogPaneView.ts"; +import { LRUCache } from "./lib/src/memory/LRUCache.ts"; +import { SerializedFileAccess } from "./storages/SerializedFileAccess.js"; +import { QueueProcessor } from "./lib/src/concurrency/processor.js"; +import { reactive, reactiveSource } from "./lib/src/dataobject/reactive.js"; +import { initializeStores } from "./common/stores.js"; +import { JournalSyncMinio } from "./lib/src/replication/journal/objectstore/JournalSyncMinio.js"; +import { LiveSyncJournalReplicator, type LiveSyncJournalReplicatorEnv } from "./lib/src/replication/journal/LiveSyncJournalReplicator.js"; +import { LiveSyncCouchDBReplicator, type LiveSyncCouchDBReplicatorEnv } from "./lib/src/replication/couchdb/LiveSyncReplicator.js"; +import type { CheckPointInfo } from "./lib/src/replication/journal/JournalSyncTypes.js"; +import { ObsHttpHandler } from "./common/ObsHttpHandler.js"; setNoticeClass(Notice); diff --git a/src/SerializedFileAccess.ts b/src/storages/SerializedFileAccess.ts similarity index 94% rename from src/SerializedFileAccess.ts rename to src/storages/SerializedFileAccess.ts index 0448e9d..2f5d066 100644 --- a/src/SerializedFileAccess.ts +++ b/src/storages/SerializedFileAccess.ts @@ -1,11 +1,11 @@ -import { type App, TFile, type DataWriteOptions, TFolder, TAbstractFile } from "./deps"; -import { serialized } from "./lib/src/lock"; -import { Logger } from "./lib/src/logger"; -import { isPlainText } from "./lib/src/path"; -import type { FilePath } from "./lib/src/types"; -import { createBinaryBlob, isDocContentSame } from "./lib/src/utils"; -import type { InternalFileInfo } from "./types"; -import { markChangesAreSame } from "./utils"; +import { type App, TFile, type DataWriteOptions, TFolder, TAbstractFile } from "../deps.ts"; +import { serialized } from "../lib/src/concurrency/lock.ts"; +import { Logger } from "../lib/src/common/logger.ts"; +import { isPlainText } from "../lib/src/string_and_binary/path.ts"; +import type { FilePath } from "../lib/src/common/types.ts"; +import { createBinaryBlob, isDocContentSame } from "../lib/src/common/utils.ts"; +import type { InternalFileInfo } from "../common/types.ts"; +import { markChangesAreSame } from "../common/utils.ts"; function getFileLockKey(file: TFile | TFolder | string) { return `fl:${typeof (file) == "string" ? file : file.path}`; diff --git a/src/StorageEventManager.ts b/src/storages/StorageEventManager.ts similarity index 93% rename from src/StorageEventManager.ts rename to src/storages/StorageEventManager.ts index 00899dc..a2e44cb 100644 --- a/src/StorageEventManager.ts +++ b/src/storages/StorageEventManager.ts @@ -1,11 +1,11 @@ -import type { SerializedFileAccess } from "./SerializedFileAccess"; -import { Plugin, TAbstractFile, TFile, TFolder } from "./deps"; -import { Logger } from "./lib/src/logger"; -import { shouldBeIgnored } from "./lib/src/path"; -import type { QueueProcessor } from "./lib/src/processor"; -import { LOG_LEVEL_NOTICE, type FilePath, type ObsidianLiveSyncSettings } from "./lib/src/types"; -import { delay } from "./lib/src/utils"; -import { type FileEventItem, type FileEventType, type FileInfo, type InternalFileInfo } from "./types"; +import type { SerializedFileAccess } from "./SerializedFileAccess.ts"; +import { Plugin, TAbstractFile, TFile, TFolder } from "../deps.ts"; +import { Logger } from "../lib/src/common/logger.ts"; +import { shouldBeIgnored } from "../lib/src/string_and_binary/path.ts"; +import type { QueueProcessor } from "../lib/src/concurrency/processor.ts"; +import { LOG_LEVEL_NOTICE, type FilePath, type ObsidianLiveSyncSettings } from "../lib/src/common/types.ts"; +import { delay } from "../lib/src/common/utils.ts"; +import { type FileEventItem, type FileEventType, type FileInfo, type InternalFileInfo } from "../common/types.ts"; export abstract class StorageEventManager { diff --git a/src/ConflictResolveModal.ts b/src/ui/ConflictResolveModal.ts similarity index 94% rename from src/ConflictResolveModal.ts rename to src/ui/ConflictResolveModal.ts index cc5f61a..e02eb64 100644 --- a/src/ConflictResolveModal.ts +++ b/src/ui/ConflictResolveModal.ts @@ -1,8 +1,8 @@ -import { App, Modal } from "./deps"; +import { App, Modal } from "../deps.ts"; import { DIFF_DELETE, DIFF_EQUAL, DIFF_INSERT } from "diff-match-patch"; -import { CANCELLED, LEAVE_TO_SUBSEQUENT, RESULT_TIMED_OUT, type diff_result } from "./lib/src/types"; -import { escapeStringToHTML } from "./lib/src/strbin"; -import { delay, sendValue, waitForValue } from "./lib/src/utils"; +import { CANCELLED, LEAVE_TO_SUBSEQUENT, RESULT_TIMED_OUT, type diff_result } from "../lib/src/common/types.ts"; +import { escapeStringToHTML } from "../lib/src/string_and_binary/strbin.ts"; +import { delay, sendValue, waitForValue } from "../lib/src/common/utils.ts"; export type MergeDialogResult = typeof LEAVE_TO_SUBSEQUENT | typeof CANCELLED | string; export class ConflictResolveModal extends Modal { diff --git a/src/DocumentHistoryModal.ts b/src/ui/DocumentHistoryModal.ts similarity index 95% rename from src/DocumentHistoryModal.ts rename to src/ui/DocumentHistoryModal.ts index 620664e..6d65993 100644 --- a/src/DocumentHistoryModal.ts +++ b/src/ui/DocumentHistoryModal.ts @@ -1,12 +1,12 @@ -import { TFile, Modal, App, DIFF_DELETE, DIFF_EQUAL, DIFF_INSERT, diff_match_patch } from "./deps"; -import { getPathFromTFile, isValidPath } from "./utils"; -import { decodeBinary, escapeStringToHTML, readString } from "./lib/src/strbin"; -import ObsidianLiveSyncPlugin from "./main"; -import { type DocumentID, type FilePathWithPrefix, type LoadedEntry, LOG_LEVEL_INFO, LOG_LEVEL_NOTICE, LOG_LEVEL_VERBOSE } from "./lib/src/types"; -import { Logger } from "./lib/src/logger"; -import { isErrorOfMissingDoc } from "./lib/src/utils_couchdb"; -import { getDocData, readContent } from "./lib/src/utils"; -import { isPlainText, stripPrefix } from "./lib/src/path"; +import { TFile, Modal, App, DIFF_DELETE, DIFF_EQUAL, DIFF_INSERT, diff_match_patch } from "../deps.ts"; +import { getPathFromTFile, isValidPath } from "../common/utils.ts"; +import { decodeBinary, escapeStringToHTML, readString } from "../lib/src/string_and_binary/strbin.ts"; +import ObsidianLiveSyncPlugin from "../main.ts"; +import { type DocumentID, type FilePathWithPrefix, type LoadedEntry, LOG_LEVEL_INFO, LOG_LEVEL_NOTICE, LOG_LEVEL_VERBOSE } from "../lib/src/common/types.ts"; +import { Logger } from "../lib/src/common/logger.ts"; +import { isErrorOfMissingDoc } from "../lib/src/pouchdb/utils_couchdb.ts"; +import { getDocData, readContent } from "../lib/src/common/utils.ts"; +import { isPlainText, stripPrefix } from "../lib/src/string_and_binary/path.ts"; function isImage(path: string) { const ext = path.split(".").splice(-1)[0].toLowerCase(); diff --git a/src/GlobalHistory.svelte b/src/ui/GlobalHistory.svelte similarity index 97% rename from src/GlobalHistory.svelte rename to src/ui/GlobalHistory.svelte index 73fcc5e..70e1856 100644 --- a/src/GlobalHistory.svelte +++ b/src/ui/GlobalHistory.svelte @@ -1,12 +1,12 @@