@vrtmrz/livesync-commonlib 0.4.1 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. package/README.md +14 -2
  2. package/dist/interfaces/FileHandler.d.ts +59 -0
  3. package/dist/interfaces/FileReflectionProvenance.d.ts +15 -1
  4. package/dist/interfaces/FileReflectionProvenance.js +11 -1
  5. package/dist/serviceFeatures/offlineScanner/fileStatus.d.ts +61 -0
  6. package/dist/serviceFeatures/offlineScanner/fileStatus.js +85 -0
  7. package/dist/serviceFeatures/offlineScanner/files.d.ts +47 -0
  8. package/dist/serviceFeatures/offlineScanner/files.js +218 -0
  9. package/dist/serviceFeatures/offlineScanner/metadata.d.ts +56 -0
  10. package/dist/serviceFeatures/offlineScanner/metadata.js +320 -0
  11. package/dist/serviceFeatures/offlineScanner/paths.d.ts +20 -0
  12. package/dist/serviceFeatures/offlineScanner/paths.js +16 -0
  13. package/dist/serviceFeatures/offlineScanner/scan.d.ts +35 -0
  14. package/dist/serviceFeatures/offlineScanner/scan.js +358 -0
  15. package/dist/serviceFeatures/offlineScanner/types.d.ts +134 -0
  16. package/dist/serviceFeatures/offlineScanner/types.js +66 -0
  17. package/dist/serviceFeatures/offlineScanner.d.ts +25 -251
  18. package/dist/serviceFeatures/offlineScanner.js +36 -860
  19. package/dist/serviceModules/ServiceFileHandlerBase/deletionRecovery.d.ts +13 -0
  20. package/dist/serviceModules/ServiceFileHandlerBase/deletionRecovery.js +194 -0
  21. package/dist/serviceModules/ServiceFileHandlerBase.d.ts +22 -1
  22. package/dist/serviceModules/ServiceFileHandlerBase.js +29 -0
  23. package/dist/services/base/KeyValueDBService.d.ts +9 -0
  24. package/dist/services/base/KeyValueDBService.js +11 -1
  25. package/docs/development.md +4 -0
  26. package/docs/offline-scanner.md +21 -0
  27. package/docs/storage-events-and-reflection.md +16 -10
  28. package/package.json +1 -1
@@ -1,260 +1,34 @@
1
- import { type DocumentID, type FilePathWithPrefix, type FilePathWithPrefixLC, type MetaEntry, type UXFileInfoStub, type ObsidianLiveSyncSettings, type LOG_LEVEL } from "../common/types.js";
2
- import { type LogFunction } from "../services/lib/logUtils.js";
3
1
  import type { NecessaryServices } from "../interfaces/ServiceModule.js";
4
- import type { IPathService } from "../services/base/IService.js";
2
+ import { type LogFunction } from "../services/lib/logUtils.js";
5
3
  import { UnresolvedErrorManager } from "../services/base/UnresolvedErrorManager.js";
6
- import { VaultScanResults, type VaultScanResult, type VaultScanOptions } from "../services/base/VaultScanResult.js";
7
- export { VaultScanResults };
8
- export type { VaultScanResult };
9
- /**
10
- * Outcome of processing one storage/database pair during an offline scan.
11
- *
12
- * A skipped pair is intentionally left unchanged by scanner policy. It is not
13
- * a scan failure, but it must not receive success side effects which would
14
- * claim that database content was reflected to storage.
15
- */
16
- export declare const FilePairProcessResults: {
17
- readonly COMPLETED: "completed";
18
- readonly SKIPPED: "skipped";
19
- readonly FAILED: "failed";
20
- };
21
- export type FilePairProcessResult = (typeof FilePairProcessResults)[keyof typeof FilePairProcessResults];
22
- export declare const MetadataDocumentNamespaces: {
23
- readonly NORMAL: "normal";
24
- readonly INTERNAL: "internal";
25
- readonly CUSTOMISATION: "customisation";
26
- readonly PLUGIN_STORAGE: "plugin-storage";
27
- };
28
- export type MetadataDocumentNamespace = (typeof MetadataDocumentNamespaces)[keyof typeof MetadataDocumentNamespaces];
29
- export declare const MetadataDocumentIdentityStatuses: {
30
- readonly CONSISTENT: "consistent";
31
- readonly EXCLUDED: "excluded";
32
- readonly UNRESOLVED: "unresolved";
33
- };
34
- export declare const OfflineScanUnresolvedReasons: {
35
- readonly DOCUMENT_ID_MISMATCH: "document-id-mismatch";
36
- readonly NAMESPACE_MISMATCH: "namespace-mismatch";
37
- };
38
- export interface OfflineScanUnresolvedDiagnostic {
39
- reason: (typeof OfflineScanUnresolvedReasons)[keyof typeof OfflineScanUnresolvedReasons];
40
- actualDocumentId: DocumentID;
41
- declaredPath: FilePathWithPrefix;
42
- expectedDocumentId?: DocumentID;
43
- actualNamespace: MetadataDocumentNamespace;
44
- declaredPathNamespace: MetadataDocumentNamespace;
45
- }
46
- export type MetadataDocumentIdentityInspection = {
47
- status: typeof MetadataDocumentIdentityStatuses.CONSISTENT;
48
- actualDocumentId: DocumentID;
49
- declaredPath: FilePathWithPrefix;
50
- expectedDocumentId: DocumentID;
51
- } | {
52
- status: typeof MetadataDocumentIdentityStatuses.EXCLUDED;
53
- actualDocumentId: DocumentID;
54
- declaredPath: FilePathWithPrefix;
55
- namespace: Exclude<MetadataDocumentNamespace, "normal">;
56
- } | {
57
- status: typeof MetadataDocumentIdentityStatuses.UNRESOLVED;
58
- diagnostic: OfflineScanUnresolvedDiagnostic;
59
- };
60
- export interface MetadataDocumentIdentityIssue {
61
- inspection: Extract<MetadataDocumentIdentityInspection, {
62
- status: typeof MetadataDocumentIdentityStatuses.UNRESOLVED;
63
- }>;
64
- sourceRevision: string | null;
65
- logicallyDeleted: boolean;
66
- conflictRevisions: string[];
67
- repairAvailable: boolean;
68
- targetAlreadyPresent: boolean;
69
- ordinaryPathAvailable: boolean;
70
- }
71
- export declare const MetadataDocumentRepairResults: {
72
- readonly COMPLETED: "completed";
73
- readonly STALE: "stale";
74
- readonly BLOCKED: "blocked";
75
- readonly FAILED: "failed";
76
- };
77
- export interface MetadataDocumentRepairRequest {
78
- actualDocumentId: DocumentID;
79
- expectedDocumentId: DocumentID;
80
- sourceRevision: string;
81
- }
82
- export type MetadataDocumentRepairResult = {
83
- status: (typeof MetadataDocumentRepairResults)[keyof typeof MetadataDocumentRepairResults];
84
- actualDocumentId: DocumentID;
85
- expectedDocumentId: DocumentID;
86
- sourceRevision: string;
87
- targetCreated: boolean;
88
- message?: string;
89
- };
90
- /**
91
- * Classify the logical Metadata namespace before platform path filtering.
92
- *
93
- * Internal, customisation, and plug-in storage entries are owned by their
94
- * dedicated synchronisation paths. The ordinary file scanner handles only the
95
- * normal namespace.
96
- */
97
- export declare function getMetadataDocumentNamespace(value: string): MetadataDocumentNamespace;
98
- /**
99
- * Inspect whether a Metadata document identifier still represents its
100
- * declared path under the active path settings.
101
- *
102
- * This check deliberately runs before any scanner action. A mismatch can be
103
- * caused by an old path-obfuscation key, a case-sensitivity change, or a
104
- * historical rename. Selecting a repair without additional evidence would be
105
- * destructive, so callers must leave an unresolved document unchanged. A
106
- * separate consistent document for the same logical path may still proceed
107
- * through ordinary path-based handling.
108
- */
109
- export declare function inspectMetadataDocumentIdentity(host: {
110
- services: {
111
- path: Pick<IPathService, "getPath" | "path2id">;
112
- };
113
- }, doc: MetaEntry): Promise<MetadataDocumentIdentityInspection>;
114
- /**
115
- * Enumerate Metadata from its actual local document IDs and report only the
116
- * entries which ordinary path-based inspection cannot address.
117
- *
118
- * Path-addressed file inspection cannot discover a document whose stored path
119
- * derives a different ID. The report therefore provides the evidence needed
120
- * by an existing host-owned repair inspector without adding a batch-repair
121
- * policy to the scanner.
122
- */
123
- export declare function inspectMetadataDocumentIdentities(host: NecessaryServices<"path" | "database" | "setting" | "vault", never>): Promise<MetadataDocumentIdentityIssue[]>;
124
- /**
125
- * Repair one previously inspected normal-file Metadata identity.
126
- *
127
- * The request identifies the exact source revision which the operator
128
- * approved. Every precondition is inspected again under the same ordered
129
- * document locks as file-event handling. The target is created and verified
130
- * before the source receives a hard tombstone. If interruption leaves that
131
- * exact target in place, the same single-entry action can safely be repeated.
132
- */
133
- export declare function repairMetadataDocumentIdentity(host: NecessaryServices<"path" | "database" | "setting" | "vault" | "keyValueDB", never>, request: MetadataDocumentRepairRequest): Promise<MetadataDocumentRepairResult>;
134
- /**
135
- * Collect deleted files that have expired according to retention policy.
136
- * @param host Services container
137
- * @param log Logging function
138
- * @returns Array of expired deletion history
4
+ import type { VaultScanResult } from "../services/base/VaultScanResult.js";
5
+ import { type FullScanOptions } from "./offlineScanner/types.js";
6
+ export { VaultScanResults } from "../services/base/VaultScanResult.js";
7
+ export type { VaultScanResult } from "../services/base/VaultScanResult.js";
8
+ export { FilePairProcessResults, MetadataDocumentNamespaces, MetadataDocumentIdentityStatuses, OfflineScanUnresolvedReasons, MetadataDocumentRepairResults, FullScanModes, ExtraOnRemote, ExtraOnLocal, } from "./offlineScanner/types.js";
9
+ export type { FilePairProcessResult, MetadataDocumentNamespace, OfflineScanUnresolvedDiagnostic, MetadataDocumentIdentityInspection, MetadataDocumentIdentityIssue, MetadataDocumentRepairRequest, MetadataDocumentRepairResult, FullScanOptions, FullScanMode, } from "./offlineScanner/types.js";
10
+ export { getMetadataDocumentNamespace, inspectMetadataDocumentIdentity, inspectMetadataDocumentIdentities, repairMetadataDocumentIdentity, collectDeletedFiles, } from "./offlineScanner/metadata.js";
11
+ export { getPathFromEntry, convertCase } from "./offlineScanner/paths.js";
12
+ export { clearOfflineScannerLastSeen } from "./offlineScanner/fileStatus.js";
13
+ export { syncFileBetweenDBandStorage, collectFilesOnStorage, collectDatabaseFiles, updateToDatabase, updateToStorage, syncStorageAndDatabase, } from "./offlineScanner/files.js";
14
+ export { getFilePairState, resolveFilePairAction, synchroniseAllFilesBetweenDBandStorage } from "./offlineScanner/scan.js";
15
+ /**
16
+ * Check configuration, suspension, and remediation policy before a full scan.
17
+ * @param host - Borrowed settings and store capabilities.
18
+ * @param errorManager - Owner of the existing scan notices.
19
+ * @param log - Logger retained by the scan call contract.
20
+ * @param showingNotice - Whether blocked-policy notices should be visible.
21
+ * @param ignoreSuspending - Allow an explicitly requested scan while watching is suspended.
22
+ * @returns Whether the current policy permits scanning; no file work is started.
139
23
  */
140
- export declare function collectDeletedFiles(host: NecessaryServices<"setting" | "database" | "path", never>, log: LogFunction): Promise<void>;
141
- /**
142
- * Get the file path from a meta entry.
143
- * This is a helper function to extract path from various document types.
144
- * @param doc Meta entry document
145
- * @returns Path string
146
- */
147
- export declare function getPathFromEntry(host: {
148
- services: {
149
- path: Pick<IPathService, "getPath">;
150
- };
151
- }, doc: MetaEntry): FilePathWithPrefix;
152
- /**
153
- * Synchronise a single file between database and storage based on freshness comparison.
154
- * @param host Services container
155
- * @param log Logging function
156
- * @param file Storage file information
157
- * @param doc Database entry
158
- */
159
- export declare function syncFileBetweenDBandStorage(host: NecessaryServices<"setting" | "vault" | "path", "storageAccess" | "fileHandler">, log: LogFunction, file: UXFileInfoStub, doc: MetaEntry, scanOptions?: VaultScanOptions): Promise<FilePairProcessResult>;
160
24
  export declare function canProceedScan(host: NecessaryServices<"keyValueDB" | "setting", never>, errorManager: UnresolvedErrorManager, log: LogFunction, showingNotice?: boolean, ignoreSuspending?: boolean): boolean;
161
25
  /**
162
- * Normalise the logical comparison key and lower case it when filename case should be handled insensitively.
163
- * @param settings
164
- * @param path
165
- * @returns
166
- */
167
- export declare function convertCase<T extends FilePathWithPrefix>(settings: ObsidianLiveSyncSettings, path: T): FilePathWithPrefixLC;
168
- export declare function collectFilesOnStorage(host: NecessaryServices<"vault", "storageAccess">, settings: ObsidianLiveSyncSettings, log: LogFunction): Promise<{
169
- storageFileNameMap: {
170
- [k: string]: UXFileInfoStub;
171
- };
172
- storageFileNames: FilePathWithPrefix[];
173
- storageFileNameCI2CS: Record<FilePathWithPrefixLC, FilePathWithPrefix>;
174
- }>;
175
- export declare function collectDatabaseFiles(host: NecessaryServices<"database" | "vault" | "path", never>, settings: ObsidianLiveSyncSettings, log: LogFunction, showingNotice: boolean): Promise<{
176
- databaseFileNameMap: Record<FilePathWithPrefix, MetaEntry>;
177
- databaseFileNames: FilePathWithPrefix[];
178
- databaseFileNameCI2CS: Record<FilePathWithPrefixLC, FilePathWithPrefix>;
179
- quarantinedFileNamesLC: Set<FilePathWithPrefixLC>;
180
- }>;
181
- export declare function updateToDatabase(host: NecessaryServices<"vault", "fileHandler">, log: LogFunction, logLevel: LOG_LEVEL, file: UXFileInfoStub): Promise<FilePairProcessResult>;
182
- export declare function updateToStorage(host: NecessaryServices<"vault" | "path", "fileHandler">, log: LogFunction, logLevel: LOG_LEVEL, w: MetaEntry): Promise<FilePairProcessResult>;
183
- export declare function syncStorageAndDatabase(host: NecessaryServices<"setting" | "vault" | "path", "storageAccess" | "fileHandler">, log: LogFunction, file: UXFileInfoStub, logLevel: LOG_LEVEL, doc: MetaEntry, scanOptions?: VaultScanOptions): Promise<FilePairProcessResult>;
184
- export declare const FullScanModes: {
185
- readonly DB_APPLY: "db-apply";
186
- readonly NEWER_WINS: "newer-wins";
187
- };
188
- export declare const ExtraOnRemote: {
189
- /**
190
- * Delete database entries if they are missing on storage.
191
- */
192
- readonly DELETE_LOCAL_MISSING: "delete-local-missing";
193
- };
194
- export declare const ExtraOnLocal: {
195
- /**
196
- * Delete local files if they were deleted on database.
197
- */
198
- readonly DELETE_DB_DELETED: "delete-db-deleted";
199
- /**
200
- * Delete local files if they are missing on database or were deleted on database.
201
- */
202
- readonly DELETE_DB_MISSING: "delete-db-missing";
203
- /**
204
- * Merge local files to database
205
- */
206
- readonly APPEND_STORAGE_ONLY: "append-storage-only";
207
- };
208
- export interface FullScanOptions extends VaultScanOptions {
209
- mode: FullScanMode;
210
- extraOnLocal?: (typeof ExtraOnLocal)[keyof typeof ExtraOnLocal];
211
- extraOnRemote?: (typeof ExtraOnRemote)[keyof typeof ExtraOnRemote];
212
- omitEvents?: boolean;
213
- showingNotice?: boolean;
214
- ignoreSuspending?: boolean;
215
- /**
216
- * Allow a completed scan containing individual file-pair failures to
217
- * satisfy ordinary application readiness. Scan preconditions remain
218
- * strict, and failed pairs remain retryable.
219
- */
220
- continueOnFileFailure?: boolean;
221
- }
222
- export type FullScanMode = (typeof FullScanModes)[keyof typeof FullScanModes];
223
- type FilePair = {
224
- file: UXFileInfoStub;
225
- doc: MetaEntry;
226
- } | {
227
- file: undefined;
228
- doc: MetaEntry;
229
- } | {
230
- file: UXFileInfoStub;
231
- doc: undefined;
232
- };
233
- type FilePairState = "storage-only" | "db-only" | "db-only-deleted" | "both" | "both-db-deleted";
234
- type FilePairAction = "update-db" | "update-storage" | "sync-newer" | "delete-local" | "delete-db" | "skip";
235
- export declare function getFilePairState(pair: FilePair): FilePairState;
236
- /**
237
- * Determine the action to be taken for a file pair based on its state and the selected scan options.
26
+ * Convert legacy notice flags or an options object into the shared scan contract.
27
+ * @param showingNoticeOrOptions - Current options or the legacy notice flag.
28
+ * @param ignoreSuspending - Legacy suspension override.
29
+ * @returns Options with the ordinary newer-wins mode supplied as the default.
238
30
  */
239
- export declare function resolveFilePairAction(state: FilePairState, options: FullScanOptions): FilePairAction;
240
- /**
241
- * Synchronise all files between database and storage based on the selected mode and options.
242
- * @param host Core
243
- * @param log Logging function
244
- * @param errorManager Error manager
245
- * @param options Full scan options
246
- * @returns The scan result for all file pairs
247
- */
248
- export declare function synchroniseAllFilesBetweenDBandStorage(host: NecessaryServices<"setting" | "vault" | "path" | "database" | "keyValueDB", "storageAccess" | "fileHandler">, log: LogFunction, errorManager: UnresolvedErrorManager, options: FullScanOptions): Promise<VaultScanResult>;
249
31
  export declare function normaliseFullScanOptions(showingNoticeOrOptions: Partial<FullScanOptions> | boolean | undefined, ignoreSuspending?: boolean): FullScanOptions;
250
- /**
251
- * Remove one path from the Offline Scanner's durable last-seen state.
252
- *
253
- * Identity repair calls this before publishing a correctly addressed target.
254
- * Otherwise an old record of local presence could make the next NEWER_WINS
255
- * scan interpret that database-only target as a later local deletion.
256
- */
257
- export declare function clearOfflineScannerLastSeen(host: NecessaryServices<"setting" | "keyValueDB", never>, path: FilePathWithPrefix): Promise<void>;
258
32
  /**
259
33
  * Perform a full scan and synchronisation between database and storage.
260
34
  * @param host Services container
@@ -268,7 +42,7 @@ export declare function performFullScan(host: NecessaryServices<"setting" | "vau
268
42
  export declare function performFullScan(host: NecessaryServices<"setting" | "vault" | "path" | "database" | "keyValueDB", "storageAccess" | "fileHandler">, log: LogFunction, errorManager: UnresolvedErrorManager, showingNotice?: boolean, ignoreSuspending?: boolean): Promise<VaultScanResult>;
269
43
  /**
270
44
  * Associate the initialiser file feature with the app lifecycle events.
271
- * This function binds initialization handlers to the appropriate lifecycle events.
45
+ * This function binds initialisation handlers to the appropriate lifecycle events.
272
46
  * @param host Services container with required dependencies
273
47
  */
274
48
  export declare function useOfflineScanner(host: NecessaryServices<"API" | "appLifecycle" | "setting" | "vault" | "path" | "database" | "keyValueDB", "storageAccess" | "fileHandler">): void;