@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.
- package/README.md +14 -2
- package/dist/interfaces/FileHandler.d.ts +59 -0
- package/dist/interfaces/FileReflectionProvenance.d.ts +15 -1
- package/dist/interfaces/FileReflectionProvenance.js +11 -1
- package/dist/serviceFeatures/offlineScanner/fileStatus.d.ts +61 -0
- package/dist/serviceFeatures/offlineScanner/fileStatus.js +85 -0
- package/dist/serviceFeatures/offlineScanner/files.d.ts +47 -0
- package/dist/serviceFeatures/offlineScanner/files.js +218 -0
- package/dist/serviceFeatures/offlineScanner/metadata.d.ts +56 -0
- package/dist/serviceFeatures/offlineScanner/metadata.js +320 -0
- package/dist/serviceFeatures/offlineScanner/paths.d.ts +20 -0
- package/dist/serviceFeatures/offlineScanner/paths.js +16 -0
- package/dist/serviceFeatures/offlineScanner/scan.d.ts +35 -0
- package/dist/serviceFeatures/offlineScanner/scan.js +358 -0
- package/dist/serviceFeatures/offlineScanner/types.d.ts +134 -0
- package/dist/serviceFeatures/offlineScanner/types.js +66 -0
- package/dist/serviceFeatures/offlineScanner.d.ts +25 -251
- package/dist/serviceFeatures/offlineScanner.js +36 -860
- package/dist/serviceModules/ServiceFileHandlerBase/deletionRecovery.d.ts +13 -0
- package/dist/serviceModules/ServiceFileHandlerBase/deletionRecovery.js +194 -0
- package/dist/serviceModules/ServiceFileHandlerBase.d.ts +22 -1
- package/dist/serviceModules/ServiceFileHandlerBase.js +29 -0
- package/dist/services/base/KeyValueDBService.d.ts +9 -0
- package/dist/services/base/KeyValueDBService.js +11 -1
- package/docs/development.md +4 -0
- package/docs/offline-scanner.md +21 -0
- package/docs/storage-events-and-reflection.md +16 -10
- package/package.json +1 -1
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
import { unique } from "octagonal-wheels/collection";
|
|
2
|
+
import { withLocks } from "octagonal-wheels/concurrency/lock.scoped";
|
|
3
|
+
import {
|
|
4
|
+
LOG_LEVEL_INFO,
|
|
5
|
+
isMetaEntry
|
|
6
|
+
} from "../../common/types.js";
|
|
7
|
+
import { isAnyNote } from "../../common/utils.js";
|
|
8
|
+
import { shouldBeIgnored } from "../../string_and_binary/path.js";
|
|
9
|
+
import { ICHeader, ICXHeader, PSCHeader } from "../../common/models/fileaccess.const.js";
|
|
10
|
+
import {
|
|
11
|
+
MetadataDocumentNamespaces,
|
|
12
|
+
MetadataDocumentIdentityStatuses,
|
|
13
|
+
OfflineScanUnresolvedReasons,
|
|
14
|
+
MetadataDocumentRepairResults
|
|
15
|
+
} from "./types.js";
|
|
16
|
+
import { convertCase, getPathFromEntry } from "./paths.js";
|
|
17
|
+
import { clearOfflineScannerLastSeen } from "./fileStatus.js";
|
|
18
|
+
function getMetadataDocumentNamespace(value) {
|
|
19
|
+
if (value.startsWith(ICXHeader)) return MetadataDocumentNamespaces.CUSTOMISATION;
|
|
20
|
+
if (value.startsWith(ICHeader)) return MetadataDocumentNamespaces.INTERNAL;
|
|
21
|
+
if (value.startsWith(PSCHeader)) return MetadataDocumentNamespaces.PLUGIN_STORAGE;
|
|
22
|
+
return MetadataDocumentNamespaces.NORMAL;
|
|
23
|
+
}
|
|
24
|
+
async function inspectMetadataDocumentIdentity(host, doc) {
|
|
25
|
+
const actualDocumentId = doc._id;
|
|
26
|
+
const declaredPath = getPathFromEntry(host, doc);
|
|
27
|
+
const actualNamespace = getMetadataDocumentNamespace(actualDocumentId);
|
|
28
|
+
const declaredPathNamespace = getMetadataDocumentNamespace(declaredPath);
|
|
29
|
+
if (actualNamespace !== MetadataDocumentNamespaces.NORMAL || declaredPathNamespace !== MetadataDocumentNamespaces.NORMAL) {
|
|
30
|
+
if (actualNamespace === declaredPathNamespace) {
|
|
31
|
+
return {
|
|
32
|
+
status: MetadataDocumentIdentityStatuses.EXCLUDED,
|
|
33
|
+
actualDocumentId,
|
|
34
|
+
declaredPath,
|
|
35
|
+
namespace: actualNamespace
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
status: MetadataDocumentIdentityStatuses.UNRESOLVED,
|
|
40
|
+
diagnostic: {
|
|
41
|
+
reason: OfflineScanUnresolvedReasons.NAMESPACE_MISMATCH,
|
|
42
|
+
actualDocumentId,
|
|
43
|
+
declaredPath,
|
|
44
|
+
actualNamespace,
|
|
45
|
+
declaredPathNamespace
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
const expectedDocumentId = await host.services.path.path2id(declaredPath);
|
|
50
|
+
if (actualDocumentId !== expectedDocumentId) {
|
|
51
|
+
return {
|
|
52
|
+
status: MetadataDocumentIdentityStatuses.UNRESOLVED,
|
|
53
|
+
diagnostic: {
|
|
54
|
+
reason: OfflineScanUnresolvedReasons.DOCUMENT_ID_MISMATCH,
|
|
55
|
+
actualDocumentId,
|
|
56
|
+
declaredPath,
|
|
57
|
+
expectedDocumentId,
|
|
58
|
+
actualNamespace,
|
|
59
|
+
declaredPathNamespace
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
status: MetadataDocumentIdentityStatuses.CONSISTENT,
|
|
65
|
+
actualDocumentId,
|
|
66
|
+
declaredPath,
|
|
67
|
+
expectedDocumentId
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
function stableValue(value) {
|
|
71
|
+
if (Array.isArray(value)) return value.map(stableValue);
|
|
72
|
+
if (value === null || typeof value !== "object") return value;
|
|
73
|
+
return Object.fromEntries(
|
|
74
|
+
Object.entries(value).filter(([, item]) => item !== void 0).sort(([left], [right]) => left.localeCompare(right)).map(([key, item]) => [key, stableValue(item)])
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
function logicalMetadataPayload(doc) {
|
|
78
|
+
return stableValue({
|
|
79
|
+
path: doc.path,
|
|
80
|
+
ctime: doc.ctime,
|
|
81
|
+
mtime: doc.mtime,
|
|
82
|
+
size: doc.size,
|
|
83
|
+
type: doc.type,
|
|
84
|
+
children: [...doc.children],
|
|
85
|
+
eden: doc.eden ?? {},
|
|
86
|
+
deleted: Boolean(doc.deleted || doc._deleted)
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
function isExactMetadataCopy(source, target) {
|
|
90
|
+
return JSON.stringify(logicalMetadataPayload(source)) === JSON.stringify(logicalMetadataPayload(target));
|
|
91
|
+
}
|
|
92
|
+
async function inspectMetadataDocumentIdentities(host) {
|
|
93
|
+
const observations = [];
|
|
94
|
+
for await (const doc of host.services.database.localDatabase.findAllNormalDocs({ conflicts: true }) || []) {
|
|
95
|
+
if (!isMetaEntry(doc)) continue;
|
|
96
|
+
const inspection = await inspectMetadataDocumentIdentity(host, doc);
|
|
97
|
+
observations.push({ doc, inspection });
|
|
98
|
+
}
|
|
99
|
+
const expectedTargetIds = unique(
|
|
100
|
+
observations.flatMap(({ inspection }) => {
|
|
101
|
+
if (inspection.status !== MetadataDocumentIdentityStatuses.UNRESOLVED) return [];
|
|
102
|
+
const { diagnostic } = inspection;
|
|
103
|
+
if (diagnostic.reason !== OfflineScanUnresolvedReasons.DOCUMENT_ID_MISMATCH || diagnostic.expectedDocumentId === void 0) {
|
|
104
|
+
return [];
|
|
105
|
+
}
|
|
106
|
+
return [diagnostic.expectedDocumentId];
|
|
107
|
+
})
|
|
108
|
+
);
|
|
109
|
+
const targetRows = /* @__PURE__ */ new Map();
|
|
110
|
+
if (expectedTargetIds.length > 0) {
|
|
111
|
+
const result = await host.services.database.localDatabase.allDocsRaw({
|
|
112
|
+
keys: expectedTargetIds,
|
|
113
|
+
include_docs: true,
|
|
114
|
+
conflicts: true
|
|
115
|
+
});
|
|
116
|
+
for (const row of result.rows) targetRows.set(row.key, row);
|
|
117
|
+
}
|
|
118
|
+
const settings = host.services.setting.currentSettings();
|
|
119
|
+
const observationsByDocumentId = new Map(observations.map((observation) => [observation.doc._id, observation]));
|
|
120
|
+
const pathClaims = /* @__PURE__ */ new Map();
|
|
121
|
+
const targetClaims = /* @__PURE__ */ new Map();
|
|
122
|
+
for (const { doc, inspection } of observations) {
|
|
123
|
+
const declaredPath = inspection.status === MetadataDocumentIdentityStatuses.UNRESOLVED ? inspection.diagnostic.declaredPath : inspection.declaredPath;
|
|
124
|
+
const declaredNamespace = getMetadataDocumentNamespace(declaredPath);
|
|
125
|
+
if (declaredNamespace === MetadataDocumentNamespaces.NORMAL) {
|
|
126
|
+
const key = convertCase(settings, declaredPath);
|
|
127
|
+
const claims = pathClaims.get(key) ?? /* @__PURE__ */ new Set();
|
|
128
|
+
claims.add(doc._id);
|
|
129
|
+
pathClaims.set(key, claims);
|
|
130
|
+
}
|
|
131
|
+
if (inspection.status === MetadataDocumentIdentityStatuses.UNRESOLVED && inspection.diagnostic.reason === OfflineScanUnresolvedReasons.DOCUMENT_ID_MISMATCH && inspection.diagnostic.expectedDocumentId !== void 0) {
|
|
132
|
+
const claims = targetClaims.get(inspection.diagnostic.expectedDocumentId) ?? /* @__PURE__ */ new Set();
|
|
133
|
+
claims.add(doc._id);
|
|
134
|
+
targetClaims.set(inspection.diagnostic.expectedDocumentId, claims);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
const entries = [];
|
|
138
|
+
for (const { doc, inspection } of observations) {
|
|
139
|
+
if (inspection.status !== MetadataDocumentIdentityStatuses.UNRESOLVED) continue;
|
|
140
|
+
const { diagnostic } = inspection;
|
|
141
|
+
let repairAvailable = false;
|
|
142
|
+
let targetAlreadyPresent = false;
|
|
143
|
+
let ordinaryPathAvailable = false;
|
|
144
|
+
if (diagnostic.reason === OfflineScanUnresolvedReasons.DOCUMENT_ID_MISMATCH && diagnostic.expectedDocumentId !== void 0) {
|
|
145
|
+
const expectedDocumentId = diagnostic.expectedDocumentId;
|
|
146
|
+
const normalisedPath = convertCase(settings, diagnostic.declaredPath);
|
|
147
|
+
const targetObservation = observationsByDocumentId.get(expectedDocumentId);
|
|
148
|
+
const targetPath = targetObservation?.inspection.status === MetadataDocumentIdentityStatuses.CONSISTENT ? targetObservation.inspection.declaredPath : void 0;
|
|
149
|
+
ordinaryPathAvailable = targetPath !== void 0 && convertCase(settings, targetPath) === normalisedPath && host.services.vault.isValidPath(targetPath) && !shouldBeIgnored(targetPath) && await host.services.vault.isTargetFile(targetPath);
|
|
150
|
+
const row = targetRows.get(expectedDocumentId);
|
|
151
|
+
const target = row?.doc;
|
|
152
|
+
const targetMetadata = target && isMetaEntry(target) ? target : void 0;
|
|
153
|
+
targetAlreadyPresent = Boolean(targetMetadata && isExactMetadataCopy(doc, targetMetadata));
|
|
154
|
+
const targetIsAvailable = !row || row.error === "not_found" || targetAlreadyPresent && !row?.value?.deleted && !targetMetadata?._deleted && !targetMetadata?.deleted && (targetMetadata?._conflicts?.length ?? 0) === 0;
|
|
155
|
+
const samePathClaims = pathClaims.get(normalisedPath) ?? /* @__PURE__ */ new Set();
|
|
156
|
+
const permittedExactPair = targetAlreadyPresent && samePathClaims.size === 2 && samePathClaims.has(doc._id) && samePathClaims.has(expectedDocumentId);
|
|
157
|
+
const pathIsUnambiguous = samePathClaims.size === 1 || permittedExactPair;
|
|
158
|
+
const targetIsUnambiguous = (targetClaims.get(expectedDocumentId)?.size ?? 0) === 1;
|
|
159
|
+
repairAvailable = Boolean(doc._rev) && !doc.deleted && !doc._deleted && (doc._conflicts?.length ?? 0) === 0 && host.services.vault.isValidPath(diagnostic.declaredPath) && await host.services.vault.isTargetFile(diagnostic.declaredPath) && pathIsUnambiguous && targetIsUnambiguous && targetIsAvailable;
|
|
160
|
+
}
|
|
161
|
+
entries.push({
|
|
162
|
+
inspection,
|
|
163
|
+
sourceRevision: doc._rev ?? null,
|
|
164
|
+
logicallyDeleted: Boolean(doc.deleted || doc._deleted),
|
|
165
|
+
conflictRevisions: [...doc._conflicts ?? []],
|
|
166
|
+
repairAvailable,
|
|
167
|
+
targetAlreadyPresent,
|
|
168
|
+
ordinaryPathAvailable
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
return entries;
|
|
172
|
+
}
|
|
173
|
+
function cloneEden(eden) {
|
|
174
|
+
return Object.fromEntries(
|
|
175
|
+
Object.entries(eden ?? {}).map(([id, chunk]) => [id, { data: chunk.data, epoch: chunk.epoch }])
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
function createReaddressedMetadata(source, expectedDocumentId) {
|
|
179
|
+
return {
|
|
180
|
+
_id: expectedDocumentId,
|
|
181
|
+
path: source.path,
|
|
182
|
+
ctime: source.ctime,
|
|
183
|
+
mtime: source.mtime,
|
|
184
|
+
size: source.size,
|
|
185
|
+
type: source.type,
|
|
186
|
+
children: [...source.children],
|
|
187
|
+
eden: cloneEden(source.eden),
|
|
188
|
+
...source.deleted === void 0 ? {} : { deleted: source.deleted }
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
async function serializedByMetadataDocumentIds(documentIds, callback) {
|
|
192
|
+
const lockKeys = [...new Set(documentIds)].sort().map((documentId) => `processFileEvent-${documentId}`);
|
|
193
|
+
return await withLocks(lockKeys, callback);
|
|
194
|
+
}
|
|
195
|
+
function findRepairEntry(entries, actualDocumentId) {
|
|
196
|
+
return entries.find(({ inspection }) => inspection.diagnostic.actualDocumentId === actualDocumentId);
|
|
197
|
+
}
|
|
198
|
+
async function repairMetadataDocumentIdentity(host, request) {
|
|
199
|
+
const baseResult = {
|
|
200
|
+
actualDocumentId: request.actualDocumentId,
|
|
201
|
+
expectedDocumentId: request.expectedDocumentId,
|
|
202
|
+
sourceRevision: request.sourceRevision,
|
|
203
|
+
targetCreated: false
|
|
204
|
+
};
|
|
205
|
+
return await serializedByMetadataDocumentIds(
|
|
206
|
+
[request.actualDocumentId, request.expectedDocumentId],
|
|
207
|
+
async () => {
|
|
208
|
+
let targetCreated = false;
|
|
209
|
+
try {
|
|
210
|
+
const entries = await inspectMetadataDocumentIdentities(host);
|
|
211
|
+
const entry = findRepairEntry(entries, request.actualDocumentId);
|
|
212
|
+
if (!entry || entry.sourceRevision !== request.sourceRevision || entry.inspection.diagnostic.reason !== OfflineScanUnresolvedReasons.DOCUMENT_ID_MISMATCH || entry.inspection.diagnostic.expectedDocumentId !== request.expectedDocumentId) {
|
|
213
|
+
return {
|
|
214
|
+
...baseResult,
|
|
215
|
+
status: MetadataDocumentRepairResults.STALE,
|
|
216
|
+
message: "The inspected source revision or expected document ID has changed."
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
if (!entry.repairAvailable) {
|
|
220
|
+
return {
|
|
221
|
+
...baseResult,
|
|
222
|
+
status: MetadataDocumentRepairResults.BLOCKED,
|
|
223
|
+
message: "The source no longer satisfies the repair preconditions."
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
const source = await host.services.database.localDatabase.getRaw(request.actualDocumentId, {
|
|
227
|
+
rev: request.sourceRevision,
|
|
228
|
+
conflicts: true
|
|
229
|
+
});
|
|
230
|
+
if (!isMetaEntry(source) || source._rev !== request.sourceRevision) {
|
|
231
|
+
return {
|
|
232
|
+
...baseResult,
|
|
233
|
+
status: MetadataDocumentRepairResults.STALE,
|
|
234
|
+
message: "The source revision changed during repair validation."
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
await clearOfflineScannerLastSeen(host, entry.inspection.diagnostic.declaredPath);
|
|
238
|
+
if (!entry.targetAlreadyPresent) {
|
|
239
|
+
await host.services.database.localDatabase.putRaw(
|
|
240
|
+
createReaddressedMetadata(source, request.expectedDocumentId)
|
|
241
|
+
);
|
|
242
|
+
targetCreated = true;
|
|
243
|
+
}
|
|
244
|
+
const target = await host.services.database.localDatabase.getRaw(
|
|
245
|
+
request.expectedDocumentId,
|
|
246
|
+
{ conflicts: true }
|
|
247
|
+
);
|
|
248
|
+
if (!isMetaEntry(target) || target.deleted || target._deleted || (target._conflicts?.length ?? 0) > 0 || !isExactMetadataCopy(source, target)) {
|
|
249
|
+
return {
|
|
250
|
+
...baseResult,
|
|
251
|
+
targetCreated,
|
|
252
|
+
status: MetadataDocumentRepairResults.FAILED,
|
|
253
|
+
message: "The repair target could not be verified as an exact local copy."
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
await host.services.database.localDatabase.removeRaw(request.actualDocumentId, request.sourceRevision);
|
|
257
|
+
return {
|
|
258
|
+
...baseResult,
|
|
259
|
+
targetCreated,
|
|
260
|
+
status: MetadataDocumentRepairResults.COMPLETED
|
|
261
|
+
};
|
|
262
|
+
} catch (error) {
|
|
263
|
+
return {
|
|
264
|
+
...baseResult,
|
|
265
|
+
targetCreated,
|
|
266
|
+
status: MetadataDocumentRepairResults.FAILED,
|
|
267
|
+
message: error instanceof Error ? error.message : `${error}`
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
);
|
|
272
|
+
}
|
|
273
|
+
async function collectDeletedFiles(host, log) {
|
|
274
|
+
const limitDays = host.services.setting.currentSettings().automaticallyDeleteMetadataOfDeletedFiles;
|
|
275
|
+
if (limitDays <= 0) return;
|
|
276
|
+
log(`Checking expired file history`);
|
|
277
|
+
const limit = Date.now() - 86400 * 1e3 * limitDays;
|
|
278
|
+
const notes = [];
|
|
279
|
+
for await (const doc of host.services.database.localDatabase.findAllDocs({ conflicts: true })) {
|
|
280
|
+
if (isAnyNote(doc)) {
|
|
281
|
+
if (doc.deleted && doc.mtime - limit < 0) {
|
|
282
|
+
if (isMetaEntry(doc)) {
|
|
283
|
+
const identity = await inspectMetadataDocumentIdentity(host, doc);
|
|
284
|
+
if (identity.status === MetadataDocumentIdentityStatuses.UNRESOLVED) {
|
|
285
|
+
log(
|
|
286
|
+
`Expired deletion history has an unresolved Metadata identity and will be left unchanged: ${identity.diagnostic.declaredPath} (${identity.diagnostic.reason})`,
|
|
287
|
+
LOG_LEVEL_INFO
|
|
288
|
+
);
|
|
289
|
+
continue;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
notes.push({
|
|
293
|
+
path: doc.path,
|
|
294
|
+
mtime: doc.mtime,
|
|
295
|
+
ttl: (doc.mtime - limit) / 1e3 / 86400,
|
|
296
|
+
doc
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
if (notes.length === 0) {
|
|
302
|
+
log("There are no old documents");
|
|
303
|
+
log(`Checking expired file history done`);
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
for (const v of notes) {
|
|
307
|
+
log(`Deletion history expired: ${v.path}`);
|
|
308
|
+
const delDoc = v.doc;
|
|
309
|
+
delDoc._deleted = true;
|
|
310
|
+
await host.services.database.localDatabase.putRaw(delDoc);
|
|
311
|
+
}
|
|
312
|
+
log(`Checking expired file history done`);
|
|
313
|
+
}
|
|
314
|
+
export {
|
|
315
|
+
collectDeletedFiles,
|
|
316
|
+
getMetadataDocumentNamespace,
|
|
317
|
+
inspectMetadataDocumentIdentities,
|
|
318
|
+
inspectMetadataDocumentIdentity,
|
|
319
|
+
repairMetadataDocumentIdentity
|
|
320
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { FilePathWithPrefix, FilePathWithPrefixLC, MetaEntry, ObsidianLiveSyncSettings } from "../../common/types.js";
|
|
2
|
+
import type { IPathService } from "../../services/base/IService.js";
|
|
3
|
+
/**
|
|
4
|
+
* Resolve Metadata through the host's path policy.
|
|
5
|
+
* @param host - Borrowed path-resolution capability.
|
|
6
|
+
* @param doc - Metadata whose logical path is required.
|
|
7
|
+
* @returns The host-resolved path, without comparison-key case folding.
|
|
8
|
+
*/
|
|
9
|
+
export declare function getPathFromEntry(host: {
|
|
10
|
+
services: {
|
|
11
|
+
path: Pick<IPathService, "getPath">;
|
|
12
|
+
};
|
|
13
|
+
}, doc: MetaEntry): FilePathWithPrefix;
|
|
14
|
+
/**
|
|
15
|
+
* Form a comparison key without changing the actual storage path.
|
|
16
|
+
* @param settings - Active path-normalisation and filename-case settings.
|
|
17
|
+
* @param path - Logical path to compare.
|
|
18
|
+
* @returns The normalised, optionally case-folded comparison identity.
|
|
19
|
+
*/
|
|
20
|
+
export declare function convertCase<T extends FilePathWithPrefix>(settings: ObsidianLiveSyncSettings, path: T): FilePathWithPrefixLC;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { getPathNormalizationVersion, normalisePathForIdentity } from "../../common/pathNormalization.js";
|
|
2
|
+
function getPathFromEntry(host, doc) {
|
|
3
|
+
const path = host.services.path.getPath(doc);
|
|
4
|
+
return path;
|
|
5
|
+
}
|
|
6
|
+
function convertCase(settings, path) {
|
|
7
|
+
const normalisedPath = normalisePathForIdentity(path, getPathNormalizationVersion(settings));
|
|
8
|
+
if (settings.handleFilenameCaseSensitive) {
|
|
9
|
+
return normalisedPath;
|
|
10
|
+
}
|
|
11
|
+
return normalisedPath.toLowerCase();
|
|
12
|
+
}
|
|
13
|
+
export {
|
|
14
|
+
convertCase,
|
|
15
|
+
getPathFromEntry
|
|
16
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { NecessaryServices } from "../../interfaces/ServiceModule.js";
|
|
2
|
+
import type { LogFunction } from "../../services/lib/logUtils.js";
|
|
3
|
+
import type { UnresolvedErrorManager } from "../../services/base/UnresolvedErrorManager.js";
|
|
4
|
+
import { type VaultScanResult } from "../../services/base/VaultScanResult.js";
|
|
5
|
+
import { type FullScanOptions, type FilePair, type FilePairState, type FilePairAction } from "./types.js";
|
|
6
|
+
/**
|
|
7
|
+
* Classify the storage and retained-Metadata observations of one pair.
|
|
8
|
+
* @param pair - Selected observations from the shared scan collection.
|
|
9
|
+
* @returns Their policy state without performing I/O or proving content equality.
|
|
10
|
+
* @throws If neither side exists, violating the pair contract.
|
|
11
|
+
*/
|
|
12
|
+
export declare function getFilePairState(pair: FilePair): FilePairState;
|
|
13
|
+
/**
|
|
14
|
+
* Select the existing action matrix without performing the action.
|
|
15
|
+
* @param state - Classified storage/database presence and deletion state.
|
|
16
|
+
* @param options - Scan mode and explicit extra-file policies.
|
|
17
|
+
* @returns The ordinary action for this policy combination.
|
|
18
|
+
* @remarks Guarded deletion recovery is selected separately by the scan plan;
|
|
19
|
+
* this matrix retains its established explicit extra-file policies.
|
|
20
|
+
*/
|
|
21
|
+
export declare function resolveFilePairAction(state: FilePairState, options: FullScanOptions): FilePairAction;
|
|
22
|
+
/**
|
|
23
|
+
* Run one scan at a time for each backing-store owner.
|
|
24
|
+
* @param host - Borrowed scan services and file-operation capabilities.
|
|
25
|
+
* @param log - Operation-local diagnostics and progress reporting.
|
|
26
|
+
* @param errorManager - Existing scan error-reporting boundary.
|
|
27
|
+
* @param options - Freshness, explicit-policy, suspension, and failure handling options.
|
|
28
|
+
* @returns The aggregate result after required bookkeeping has been attempted.
|
|
29
|
+
* @remarks File processing retains ten scanner slots; deletion recovery shares
|
|
30
|
+
* its separate three-file admission limit. The scan reuses one collection.
|
|
31
|
+
* Enabled recovery awaits the final map write; other policies retain their
|
|
32
|
+
* existing scheduled-save contract.
|
|
33
|
+
* @throws If preparation or collection fails before a per-file result can be reported.
|
|
34
|
+
*/
|
|
35
|
+
export declare function synchroniseAllFilesBetweenDBandStorage(host: NecessaryServices<"setting" | "vault" | "path" | "database" | "keyValueDB", "storageAccess" | "fileHandler">, log: LogFunction, errorManager: UnresolvedErrorManager, options: FullScanOptions): Promise<VaultScanResult>;
|