@vrtmrz/livesync-commonlib 0.4.1 → 0.4.3
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 +16 -2
- package/dist/API/DirectFileManipulatorV2.d.ts +1 -0
- package/dist/API/DirectFileManipulatorV2.js +3 -1
- package/dist/API/processSetting.d.ts +1 -0
- package/dist/API/processSetting.js +3 -0
- package/dist/common/models/setting.const.defaults.js +1 -0
- package/dist/common/models/setting.const.qr.js +2 -1
- package/dist/common/models/setting.encryption.d.ts +2 -0
- package/dist/common/models/setting.encryption.js +6 -0
- package/dist/common/models/setting.lifecycle.js +7 -2
- package/dist/common/models/setting.policy.d.ts +4 -0
- package/dist/common/models/setting.policy.js +9 -0
- package/dist/common/models/setting.type.d.ts +2 -0
- package/dist/common/models/shared.definition.configNames.js +5 -0
- package/dist/common/models/tweak.definition.d.ts +1 -0
- package/dist/common/settingConstants.d.ts +1 -0
- package/dist/common/utils.js +5 -4
- package/dist/diagnostics/couchdb.js +4 -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/managers/ChunkFetcher.js +27 -4
- package/dist/managers/chunkFetcher.helper.js +1 -1
- package/dist/pouchdb/StreamingFetch.d.ts +1 -2
- package/dist/pouchdb/encryption.d.ts +5 -10
- package/dist/pouchdb/encryption.eden.d.ts +11 -0
- package/dist/pouchdb/encryption.eden.js +37 -0
- package/dist/pouchdb/encryption.js +67 -63
- package/dist/pouchdb/encryption.policy.d.ts +9 -0
- package/dist/pouchdb/encryption.policy.js +125 -0
- package/dist/replication/UnencryptedContentRejectedError.d.ts +16 -0
- package/dist/replication/UnencryptedContentRejectedError.js +44 -0
- package/dist/replication/couchdb/LiveSyncReplicator.js +41 -4
- package/dist/replication/index.d.ts +2 -0
- package/dist/replication/index.js +3 -0
- package/dist/replication/trystero/TrysteroReplicator.d.ts +2 -0
- package/dist/replication/unencryptedContentMessages.d.ts +8 -0
- package/dist/replication/unencryptedContentMessages.js +12 -0
- 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/Rebuilder.js +28 -4
- 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/dist/services/base/RemoteConnection.d.ts +2 -0
- package/dist/services/base/RemoteService.js +2 -1
- package/dist/services/base/SettingService.js +2 -0
- package/dist/settings.d.ts +2 -1
- package/dist/settings.js +2 -0
- package/dist/worker/bgWorker.js +1 -1
- package/docs/development.md +4 -0
- package/docs/offline-scanner.md +22 -0
- package/docs/settings-lifecycle.md +4 -0
- package/docs/storage-events-and-reflection.md +16 -10
- package/package.json +1 -1
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getUnencryptedContentRejectionMessage } from "../replication/unencryptedContentMessages.js";
|
|
1
2
|
import { FlagFilesHumanReadable } from "../common/models/redflag.const.js";
|
|
2
3
|
import { REMOTE_COUCHDB, REMOTE_MINIO, REMOTE_P2P } from "../common/models/setting.const.js";
|
|
3
4
|
import { DEFAULT_SETTINGS } from "../common/models/setting.const.defaults.js";
|
|
@@ -18,6 +19,10 @@ import {
|
|
|
18
19
|
} from "../pouchdb/StreamingFetch.js";
|
|
19
20
|
import { getConfiguredFunctionsForEncryption } from "../pouchdb/encryption.js";
|
|
20
21
|
import { AuthorizationHeaderGenerator, generateCredentialObject } from "../replication/httplib.js";
|
|
22
|
+
import {
|
|
23
|
+
getUnencryptedContentRejection,
|
|
24
|
+
isUnencryptedContentRejectedError
|
|
25
|
+
} from "../replication/UnencryptedContentRejectedError.js";
|
|
21
26
|
import { isRemediationModeActive, parseHeaderValues } from "../common/utils.js";
|
|
22
27
|
import { sizeToHumanReadable } from "octagonal-wheels/number";
|
|
23
28
|
import { REMOTE_RESOURCE_KINDS } from "../replication/index.js";
|
|
@@ -541,13 +546,16 @@ Are you sure you wish to proceed?`;
|
|
|
541
546
|
let fastForwardResource;
|
|
542
547
|
let fastForward;
|
|
543
548
|
try {
|
|
544
|
-
const
|
|
549
|
+
const decrypt = settings.encrypt ? getConfiguredFunctionsForEncryption(
|
|
545
550
|
settings.passphrase,
|
|
546
551
|
false,
|
|
547
552
|
false,
|
|
548
553
|
() => securitySeed.read(),
|
|
549
|
-
settings.E2EEAlgorithm
|
|
550
|
-
|
|
554
|
+
settings.E2EEAlgorithm,
|
|
555
|
+
false,
|
|
556
|
+
void 0,
|
|
557
|
+
settings.acceptUnencryptedContent
|
|
558
|
+
).outgoing : async (doc) => doc;
|
|
551
559
|
if (startsFresh && !settings.doNotSuspendOnFetching && (await localDB.info()).doc_count === 0) {
|
|
552
560
|
fastForwardResource = await this.replicator.createRemoteResource(
|
|
553
561
|
REMOTE_RESOURCE_KINDS.INITIAL_FETCH_FAST_FORWARD,
|
|
@@ -561,7 +569,7 @@ Are you sure you wish to proceed?`;
|
|
|
561
569
|
localDB,
|
|
562
570
|
remote,
|
|
563
571
|
authHeader,
|
|
564
|
-
|
|
572
|
+
decrypt,
|
|
565
573
|
since,
|
|
566
574
|
(progress) => {
|
|
567
575
|
this._log(
|
|
@@ -580,6 +588,22 @@ Total bytes fetched: ${sizeToHumanReadable(progress.totalBytes)}`,
|
|
|
580
588
|
);
|
|
581
589
|
break;
|
|
582
590
|
} catch (ex) {
|
|
591
|
+
if (isUnencryptedContentRejectedError(ex)) {
|
|
592
|
+
this._log(
|
|
593
|
+
getUnencryptedContentRejectionMessage("fast-fetch"),
|
|
594
|
+
LOG_LEVEL_NOTICE,
|
|
595
|
+
"fetch-init-plaintext-rejected"
|
|
596
|
+
);
|
|
597
|
+
const rejection = getUnencryptedContentRejection(ex);
|
|
598
|
+
if (rejection) {
|
|
599
|
+
this._log(
|
|
600
|
+
`Fast Fetch rejected ${rejection.contentKind}: ${JSON.stringify(rejection.documentId)}`,
|
|
601
|
+
LOG_LEVEL_VERBOSE,
|
|
602
|
+
"fetch-init-plaintext-rejected"
|
|
603
|
+
);
|
|
604
|
+
}
|
|
605
|
+
throw ex;
|
|
606
|
+
}
|
|
583
607
|
if (!isRetryableStreamingFetchFailure(ex) || attempt >= FAST_FETCH_RETRY_DELAYS.length) throw ex;
|
|
584
608
|
checkpoint = await this.getFastFetchCheckpoint(remote);
|
|
585
609
|
since = checkpoint?.sequence ?? since;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { MetaEntry } from "../../common/types.js";
|
|
2
|
+
import type { DeletionRecoveryResult } from "../../interfaces/FileHandler.js";
|
|
3
|
+
import type { FileHandlerContext } from "./context.js";
|
|
4
|
+
/**
|
|
5
|
+
* Verify and recover one retained logical deletion without creating revision history.
|
|
6
|
+
* @param ctx - Captured services, state, and dynamic host boundaries.
|
|
7
|
+
* @param expected - The exact logical deletion selected by the ordinary scan.
|
|
8
|
+
* @param cleanupOnly - Require current absence and clear bookkeeping without reading or deleting a file.
|
|
9
|
+
* @returns Separate observed file, provenance, and completion outcomes, including verification failures.
|
|
10
|
+
* @remarks A shared three-operation permit precedes the document lock and all I/O. The lock
|
|
11
|
+
* excludes other handlers, while final observations conservatively detect external changes.
|
|
12
|
+
*/
|
|
13
|
+
export declare function recoverDatabaseDeletion(ctx: FileHandlerContext, expected: MetaEntry, cleanupOnly?: boolean): Promise<DeletionRecoveryResult>;
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { Semaphore, withSemaphore } from "octagonal-wheels/concurrency/semaphore";
|
|
2
|
+
import { TARGET_IS_NEW } from "../../common/models/shared.const.symbols.js";
|
|
3
|
+
import { isDocContentSame, readContent } from "../../common/utils.js";
|
|
4
|
+
import { isFilePath } from "../../string_and_binary/path.js";
|
|
5
|
+
import { withFileEventPaths } from "./locking.js";
|
|
6
|
+
import {
|
|
7
|
+
contentEvidence,
|
|
8
|
+
getProvenancePath,
|
|
9
|
+
hasContentHash,
|
|
10
|
+
readProvenanceSnapshot,
|
|
11
|
+
sameProvenance
|
|
12
|
+
} from "./provenance.js";
|
|
13
|
+
import { isCurrentFileSelected, isCurrentPathSelected } from "./selection.js";
|
|
14
|
+
import { isFolderInfo } from "./storage.js";
|
|
15
|
+
const recoveryPermits = /* @__PURE__ */ new WeakMap();
|
|
16
|
+
function progressAttempt(attempt, progress) {
|
|
17
|
+
Object.assign(attempt, progress);
|
|
18
|
+
}
|
|
19
|
+
async function recoverDatabaseDeletion(ctx, expected, cleanupOnly = false) {
|
|
20
|
+
const attempt = {
|
|
21
|
+
ctx,
|
|
22
|
+
expected,
|
|
23
|
+
path: expected.path,
|
|
24
|
+
file: "unknown",
|
|
25
|
+
provenance: "unchanged",
|
|
26
|
+
phase: "admission"
|
|
27
|
+
};
|
|
28
|
+
if (!ctx.provenance?.listPaths) return outcome(attempt, "deferred", "capability-unavailable");
|
|
29
|
+
let semaphore = recoveryPermits.get(ctx.provenance);
|
|
30
|
+
if (!semaphore) {
|
|
31
|
+
semaphore = Semaphore(3);
|
|
32
|
+
recoveryPermits.set(ctx.provenance, semaphore);
|
|
33
|
+
}
|
|
34
|
+
try {
|
|
35
|
+
return await withSemaphore(semaphore, () => {
|
|
36
|
+
progressAttempt(attempt, { path: ctx.host.getPath(expected) });
|
|
37
|
+
return withFileEventPaths(ctx, [attempt.path], () => recoverUnderLock(attempt, cleanupOnly));
|
|
38
|
+
});
|
|
39
|
+
} catch (error) {
|
|
40
|
+
return { ...outcome(attempt, "failed", `${attempt.phase}-failed`), error };
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
async function recoverUnderLock(attempt, cleanupOnly) {
|
|
44
|
+
const { ctx, expected, path } = attempt;
|
|
45
|
+
progressAttempt(attempt, { phase: "eligibility" });
|
|
46
|
+
if (!validDeletion(expected) || !isFilePath(path) || await ctx.path.path2id(path) !== expected._id) {
|
|
47
|
+
return outcome(attempt, "deferred", "invalid-deletion");
|
|
48
|
+
}
|
|
49
|
+
if (!await isCurrentPathSelected(ctx, path)) return outcome(attempt, "deferred", "not-selected");
|
|
50
|
+
if (!await sameCurrentDeletion(attempt)) return outcome(attempt, "deferred", "database-changed");
|
|
51
|
+
const stub = await ctx.host.storage().getStub(path);
|
|
52
|
+
progressAttempt(attempt, {
|
|
53
|
+
file: stub === null ? "absent" : "present",
|
|
54
|
+
provenance: stub === null ? "pending" : "unchanged"
|
|
55
|
+
});
|
|
56
|
+
if (isFolderInfo(stub)) return outcome(attempt, "deferred", "storage-identity-changed");
|
|
57
|
+
if (stub !== null && (stub.isInternal || stub.path !== path)) {
|
|
58
|
+
return outcome(attempt, "deferred", "storage-identity-changed");
|
|
59
|
+
}
|
|
60
|
+
if (cleanupOnly && stub !== null) return outcome(attempt, "deferred", "file-present");
|
|
61
|
+
if (stub && (!await isCurrentFileSelected(ctx, stub) || ctx.path.compareFileFreshness(stub, expected) !== TARGET_IS_NEW)) {
|
|
62
|
+
return outcome(attempt, "deferred", "file-not-eligible");
|
|
63
|
+
}
|
|
64
|
+
progressAttempt(attempt, { phase: "provenance-read" });
|
|
65
|
+
const record = await readProvenanceSnapshot(ctx, path, true);
|
|
66
|
+
if (!stub) return await clearAbsentProvenance(attempt, record);
|
|
67
|
+
if (!record?.revision) return outcome(attempt, "deferred", "provenance-missing");
|
|
68
|
+
if (hasContentHash(record) && record.contentSize !== stub.stat.size) {
|
|
69
|
+
return outcome(attempt, "deferred", "content-size-mismatch");
|
|
70
|
+
}
|
|
71
|
+
return await verifyPresentFile(attempt, { ...stub, stat: { ...stub.stat } }, record);
|
|
72
|
+
}
|
|
73
|
+
async function verifyPresentFile(attempt, stub, record) {
|
|
74
|
+
const { ctx, path } = attempt;
|
|
75
|
+
let base;
|
|
76
|
+
if (!hasContentHash(record)) {
|
|
77
|
+
progressAttempt(attempt, { phase: "base-read" });
|
|
78
|
+
base = await ctx.host.db().fetchEntry(path, record.revision, true, true, false);
|
|
79
|
+
if (!base) return outcome(attempt, "failed", "base-unavailable");
|
|
80
|
+
if (base._rev !== record.revision || base.deleted || base._deleted || ctx.host.getPath(base) !== path) {
|
|
81
|
+
return outcome(attempt, "deferred", "base-not-usable");
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
progressAttempt(attempt, { phase: "body-read" });
|
|
85
|
+
const observed = await ctx.host.readFileFromStub(stub);
|
|
86
|
+
const file = { ...observed, stat: { ...observed.stat } };
|
|
87
|
+
if (!sameFileObservation(stub, file)) return outcome(attempt, "deferred", "storage-changed");
|
|
88
|
+
if (hasContentHash(record)) {
|
|
89
|
+
progressAttempt(attempt, { phase: "content-hash" });
|
|
90
|
+
const evidence = await contentEvidence(ctx, file.body);
|
|
91
|
+
if (!evidence.contentHash) return outcome(attempt, "failed", "content-hash-unavailable");
|
|
92
|
+
if (evidence.contentSize !== record.contentSize || evidence.contentHash !== record.contentHash) {
|
|
93
|
+
return outcome(attempt, "deferred", "content-hash-mismatch");
|
|
94
|
+
}
|
|
95
|
+
} else if (!base || !await isDocContentSame(readContent(base), file.body)) {
|
|
96
|
+
return outcome(attempt, "deferred", "base-content-mismatch");
|
|
97
|
+
}
|
|
98
|
+
base = void 0;
|
|
99
|
+
progressAttempt(attempt, { phase: "final-verification" });
|
|
100
|
+
const latest = await ctx.host.storage().getStub(path);
|
|
101
|
+
if (!latest || isFolderInfo(latest) || !sameFileObservation(latest, file)) {
|
|
102
|
+
progressAttempt(attempt, { file: latest === null ? "absent" : "present", provenance: "unchanged" });
|
|
103
|
+
return outcome(attempt, "deferred", "storage-changed");
|
|
104
|
+
}
|
|
105
|
+
const readFinal = await ctx.host.readFileFromStub(latest);
|
|
106
|
+
const final = { ...readFinal, stat: { ...readFinal.stat } };
|
|
107
|
+
if (!sameFileObservation(final, file) || !await isDocContentSame(final.body, file.body)) {
|
|
108
|
+
return outcome(attempt, "deferred", "storage-changed");
|
|
109
|
+
}
|
|
110
|
+
if (!sameProvenance(await readProvenanceSnapshot(ctx, path, true), record)) {
|
|
111
|
+
return outcome(attempt, "deferred", "provenance-changed");
|
|
112
|
+
}
|
|
113
|
+
if (!await sameCurrentDeletion(attempt)) return outcome(attempt, "deferred", "database-changed");
|
|
114
|
+
if (!await isCurrentFileSelected(ctx, final)) return outcome(attempt, "deferred", "not-selected");
|
|
115
|
+
if (ctx.path.compareFileFreshness(final, attempt.expected) !== TARGET_IS_NEW) {
|
|
116
|
+
return outcome(attempt, "deferred", "file-not-eligible");
|
|
117
|
+
}
|
|
118
|
+
const target = await ctx.host.storage().getStub(path);
|
|
119
|
+
if (!target || isFolderInfo(target) || !sameFileObservation(target, file)) {
|
|
120
|
+
progressAttempt(attempt, { file: target === null ? "absent" : "present", provenance: "unchanged" });
|
|
121
|
+
return outcome(attempt, "deferred", "storage-changed");
|
|
122
|
+
}
|
|
123
|
+
return await removeAndConfirm(attempt, record);
|
|
124
|
+
}
|
|
125
|
+
async function removeAndConfirm(attempt, record) {
|
|
126
|
+
const { ctx, path } = attempt;
|
|
127
|
+
progressAttempt(attempt, { phase: "remove", file: "unknown", provenance: "pending" });
|
|
128
|
+
try {
|
|
129
|
+
await ctx.host.storage().deleteVaultItem(path);
|
|
130
|
+
} catch (error) {
|
|
131
|
+
progressAttempt(attempt, { error, warning: "storage-post-removal-error" });
|
|
132
|
+
}
|
|
133
|
+
progressAttempt(attempt, { phase: "removal-verification" });
|
|
134
|
+
const current = await ctx.host.storage().getStub(path);
|
|
135
|
+
if (current !== null) {
|
|
136
|
+
progressAttempt(attempt, { file: "present", provenance: "unchanged", warning: void 0 });
|
|
137
|
+
return outcome(attempt, "failed", attempt.error ? "removal-failed" : "removal-no-effect");
|
|
138
|
+
}
|
|
139
|
+
progressAttempt(attempt, { file: "absent", provenance: "pending" });
|
|
140
|
+
return await clearAbsentProvenance(attempt, record);
|
|
141
|
+
}
|
|
142
|
+
async function clearAbsentProvenance(attempt, record) {
|
|
143
|
+
const { ctx, path } = attempt;
|
|
144
|
+
progressAttempt(attempt, { phase: "provenance-cleanup" });
|
|
145
|
+
if (!await isCurrentPathSelected(ctx, path)) return outcome(attempt, "deferred", "not-selected");
|
|
146
|
+
if (!await sameCurrentDeletion(attempt)) return outcome(attempt, "deferred", "database-changed");
|
|
147
|
+
const latest = await readProvenanceSnapshot(ctx, path, true);
|
|
148
|
+
if (!sameProvenance(latest, record)) return outcome(attempt, "deferred", "provenance-changed");
|
|
149
|
+
const target = await ctx.host.storage().getStub(path);
|
|
150
|
+
if (target !== null) {
|
|
151
|
+
progressAttempt(attempt, { file: "present", provenance: "unchanged" });
|
|
152
|
+
return outcome(attempt, "deferred", "file-recreated");
|
|
153
|
+
}
|
|
154
|
+
if (latest) await ctx.provenance.delete(getProvenancePath(ctx, path));
|
|
155
|
+
progressAttempt(attempt, { file: "absent", provenance: "cleared" });
|
|
156
|
+
return outcome(attempt, "applied", "deletion-confirmed");
|
|
157
|
+
}
|
|
158
|
+
async function sameCurrentDeletion({ ctx, expected, path }) {
|
|
159
|
+
const current = await ctx.host.db().fetchEntryMeta(path, void 0, true);
|
|
160
|
+
if (!current || !validDeletion(current)) return false;
|
|
161
|
+
if (current._id !== expected._id || current._rev !== expected._rev) return false;
|
|
162
|
+
if (ctx.host.getPath(current) !== path) return false;
|
|
163
|
+
if (await ctx.path.path2id(path) !== current._id) return false;
|
|
164
|
+
return (await ctx.host.db().getConflictedRevs(path)).length === 0;
|
|
165
|
+
}
|
|
166
|
+
function validDeletion(entry) {
|
|
167
|
+
return !!entry._id && !!entry._rev && entry.deleted === true && !entry._deleted && ["notes", "plain", "newnote"].includes(entry.type) && Array.isArray(entry.children) && Number.isFinite(entry.mtime) && Number.isFinite(entry.ctime) && Number.isSafeInteger(entry.size) && entry.size >= 0 && !entry._conflicts?.length;
|
|
168
|
+
}
|
|
169
|
+
function sameFileObservation(left, right) {
|
|
170
|
+
return !left.isInternal && !left.isFolder && left.path === right.path && left.stat.type === "file" && left.stat.mtime === right.stat.mtime && left.stat.ctime === right.stat.ctime && left.stat.size === right.stat.size;
|
|
171
|
+
}
|
|
172
|
+
function outcome(attempt, status, reason) {
|
|
173
|
+
const diagnostics = {
|
|
174
|
+
reason,
|
|
175
|
+
phase: attempt.phase,
|
|
176
|
+
...attempt.warning ? { warning: attempt.warning } : {},
|
|
177
|
+
...attempt.error ? { error: attempt.error } : {}
|
|
178
|
+
};
|
|
179
|
+
const { file, provenance } = attempt;
|
|
180
|
+
if (file === "absent" && provenance === "cleared" && status !== "deferred") {
|
|
181
|
+
return { ...diagnostics, status, file, provenance };
|
|
182
|
+
}
|
|
183
|
+
if (provenance === "unchanged" && status !== "applied") {
|
|
184
|
+
return { ...diagnostics, status, file, provenance };
|
|
185
|
+
}
|
|
186
|
+
if (provenance === "pending" && status !== "applied") {
|
|
187
|
+
if (file === "absent") return { ...diagnostics, status, file, provenance };
|
|
188
|
+
if (file === "unknown" && status === "failed") return { ...diagnostics, status, file, provenance };
|
|
189
|
+
}
|
|
190
|
+
throw new Error("Inconsistent deletion recovery outcome");
|
|
191
|
+
}
|
|
192
|
+
export {
|
|
193
|
+
recoverDatabaseDeletion
|
|
194
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { AnyEntry, FilePath, FilePathWithPrefix, MetaEntry, UXFileInfo, UXFileInfoStub, UXInternalFileInfoStub } from "../common/types.js";
|
|
2
|
-
import type { IFileHandler, StoreFileOptions } from "../interfaces/FileHandler.js";
|
|
2
|
+
import type { DeletionRecoveryResult, IFileHandler, StoreFileOptions } from "../interfaces/FileHandler.js";
|
|
3
3
|
import type { DatabaseFileAccess } from "../interfaces/DatabaseFileAccess.js";
|
|
4
4
|
import type { StorageAccess } from "../interfaces/StorageAccess.js";
|
|
5
5
|
import { ServiceModuleBase } from "./ServiceModuleBase.js";
|
|
@@ -61,6 +61,27 @@ export declare abstract class ServiceFileHandlerBase extends ServiceModuleBase<S
|
|
|
61
61
|
* @remarks Acquire the document lock while checking a metadata-only hint. No revision or file content is written; inspection failures are logged and return false.
|
|
62
62
|
*/
|
|
63
63
|
canSkipUnchangedFile(info: UXFileInfoStub, expected: MetaEntry): Promise<boolean>;
|
|
64
|
+
/**
|
|
65
|
+
* Check the host's explicit deletion-recovery capability without store access.
|
|
66
|
+
* @returns Whether complete provenance-key enumeration is available.
|
|
67
|
+
* @remarks This pure capability check never enumerates keys or reads provenance values.
|
|
68
|
+
*/
|
|
69
|
+
supportsDeletionRecovery(): boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Enumerate the host's existing provenance keys for absent-file cleanup discovery.
|
|
72
|
+
* @returns Complete namespace-scoped provenance paths; host access errors propagate.
|
|
73
|
+
* @remarks Unsupported hosts reject. This operation reads keys without loading bodies or records.
|
|
74
|
+
*/
|
|
75
|
+
listDeletionRecoveryPaths(): Promise<FilePathWithPrefix[]>;
|
|
76
|
+
/**
|
|
77
|
+
* Recover one exact database deletion while preserving unproved or changed local content.
|
|
78
|
+
* @param expected - The current logical deletion selected by the ordinary scanner.
|
|
79
|
+
* @param cleanupOnly - Require an absent file and clear only stale device-local bookkeeping.
|
|
80
|
+
* @returns Separate observed file, provenance, and completion outcomes.
|
|
81
|
+
* @remarks The responsibility acquires a shared recovery permit before its document lock;
|
|
82
|
+
* verification failures are reported without changing normal incoming or save policy.
|
|
83
|
+
*/
|
|
84
|
+
recoverDatabaseDeletion(expected: MetaEntry, cleanupOnly?: boolean): Promise<DeletionRecoveryResult>;
|
|
64
85
|
/**
|
|
65
86
|
* Record an unchanged current revision after rechecking storage and database evidence.
|
|
66
87
|
* @param info - The supplied file observation or path.
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
} from "./ServiceFileHandlerBase/deletion.js";
|
|
11
11
|
import { renameFileInDB } from "./ServiceFileHandlerBase/renaming.js";
|
|
12
12
|
import { dbToStorageWithSpecificRev, dbToStorage } from "./ServiceFileHandlerBase/reflection.js";
|
|
13
|
+
import { recoverDatabaseDeletion } from "./ServiceFileHandlerBase/deletionRecovery.js";
|
|
13
14
|
import { createAllChunks } from "./ServiceFileHandlerBase/chunks.js";
|
|
14
15
|
import { ServiceModuleBase } from "./ServiceModuleBase.js";
|
|
15
16
|
import {} from "./ServiceFileHandlerBase/context.js";
|
|
@@ -135,6 +136,34 @@ class ServiceFileHandlerBase extends ServiceModuleBase {
|
|
|
135
136
|
async canSkipUnchangedFile(info, expected) {
|
|
136
137
|
return await canSkipUnchangedFile(this.context, info, expected);
|
|
137
138
|
}
|
|
139
|
+
/**
|
|
140
|
+
* Check the host's explicit deletion-recovery capability without store access.
|
|
141
|
+
* @returns Whether complete provenance-key enumeration is available.
|
|
142
|
+
* @remarks This pure capability check never enumerates keys or reads provenance values.
|
|
143
|
+
*/
|
|
144
|
+
supportsDeletionRecovery() {
|
|
145
|
+
return !!this.context.provenance?.listPaths;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Enumerate the host's existing provenance keys for absent-file cleanup discovery.
|
|
149
|
+
* @returns Complete namespace-scoped provenance paths; host access errors propagate.
|
|
150
|
+
* @remarks Unsupported hosts reject. This operation reads keys without loading bodies or records.
|
|
151
|
+
*/
|
|
152
|
+
async listDeletionRecoveryPaths() {
|
|
153
|
+
if (!this.context.provenance?.listPaths) throw new Error("Deletion recovery is unavailable for this host");
|
|
154
|
+
return await this.context.provenance.listPaths();
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Recover one exact database deletion while preserving unproved or changed local content.
|
|
158
|
+
* @param expected - The current logical deletion selected by the ordinary scanner.
|
|
159
|
+
* @param cleanupOnly - Require an absent file and clear only stale device-local bookkeeping.
|
|
160
|
+
* @returns Separate observed file, provenance, and completion outcomes.
|
|
161
|
+
* @remarks The responsibility acquires a shared recovery permit before its document lock;
|
|
162
|
+
* verification failures are reported without changing normal incoming or save policy.
|
|
163
|
+
*/
|
|
164
|
+
async recoverDatabaseDeletion(expected, cleanupOnly = false) {
|
|
165
|
+
return await recoverDatabaseDeletion(this.context, expected, cleanupOnly);
|
|
166
|
+
}
|
|
138
167
|
/**
|
|
139
168
|
* Record an unchanged current revision after rechecking storage and database evidence.
|
|
140
169
|
* @param info - The supplied file observation or path.
|
|
@@ -33,6 +33,15 @@ export declare abstract class KeyValueDBService<T extends ServiceContext = Servi
|
|
|
33
33
|
private _everyOnInitializeDatabase;
|
|
34
34
|
private _everyOnloadAfterLoadSettings;
|
|
35
35
|
constructor(context: T, dependencies: KeyValueDBDependencies<T>);
|
|
36
|
+
/**
|
|
37
|
+
* Create an inert namespaced handle over the service's current database.
|
|
38
|
+
* @param kind - Namespace identifier; stored keys receive this identifier and a trailing hyphen.
|
|
39
|
+
* @returns A handle whose operations resolve the current database when invoked.
|
|
40
|
+
* @remarks Construction performs no database I/O. Operations fail if the store
|
|
41
|
+
* is not ready. For keys, an undefined upper bound means the complete remaining
|
|
42
|
+
* namespace, including Unicode and empty keys. Explicit bounds are inclusive,
|
|
43
|
+
* and the optional count is passed to the database unchanged.
|
|
44
|
+
*/
|
|
36
45
|
openSimpleStore<T>(kind: string): {
|
|
37
46
|
get: (key: string) => Promise<T>;
|
|
38
47
|
set: (key: string, value: unknown) => Promise<void>;
|
|
@@ -101,6 +101,15 @@ class KeyValueDBService extends ServiceBase {
|
|
|
101
101
|
this.databaseEvents.onCloseDatabase.addHandler(this._onOtherDatabaseClose.bind(this));
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
|
+
/**
|
|
105
|
+
* Create an inert namespaced handle over the service's current database.
|
|
106
|
+
* @param kind - Namespace identifier; stored keys receive this identifier and a trailing hyphen.
|
|
107
|
+
* @returns A handle whose operations resolve the current database when invoked.
|
|
108
|
+
* @remarks Construction performs no database I/O. Operations fail if the store
|
|
109
|
+
* is not ready. For keys, an undefined upper bound means the complete remaining
|
|
110
|
+
* namespace, including Unicode and empty keys. Explicit bounds are inclusive,
|
|
111
|
+
* and the optional count is passed to the database unchanged.
|
|
112
|
+
*/
|
|
104
113
|
openSimpleStore(kind) {
|
|
105
114
|
const getDB = () => {
|
|
106
115
|
if (!this._kvDB) {
|
|
@@ -120,8 +129,9 @@ class KeyValueDBService extends ServiceBase {
|
|
|
120
129
|
await getDB().del(`${prefix}${key}`);
|
|
121
130
|
},
|
|
122
131
|
keys: async (from, to, count) => {
|
|
132
|
+
const upperBound = to === void 0 ? `${prefix.slice(0, -1)}.` : `${prefix}${to || ""}`;
|
|
123
133
|
const ret = await getDB().keys(
|
|
124
|
-
IDBKeyRange.bound(`${prefix}${from || ""}`,
|
|
134
|
+
IDBKeyRange.bound(`${prefix}${from || ""}`, upperBound, false, to === void 0),
|
|
125
135
|
count
|
|
126
136
|
);
|
|
127
137
|
return ret.map((e) => (typeof e === "string" ? e : JSON.stringify(e)).toString()).filter((e) => e.startsWith(prefix)).map((e) => e.substring(prefix.length));
|
|
@@ -8,6 +8,8 @@ export interface RemoteConnectionOpenOptions {
|
|
|
8
8
|
readonly encryptionAlgorithm?: E2EEAlgorithm;
|
|
9
9
|
/** Apply HKDF Metadata encryption to obfuscated internal entries on writes. */
|
|
10
10
|
readonly encryptInternalMetadata?: boolean;
|
|
11
|
+
/** Accept plaintext file content on reads while E2EE is enabled. */
|
|
12
|
+
readonly acceptUnencryptedContent?: boolean;
|
|
11
13
|
/** Use HTTP headers alone for cache control; an absent value is false. */
|
|
12
14
|
readonly useCouchDBCacheControlHeadersOnly?: boolean;
|
|
13
15
|
/**
|
|
@@ -316,7 +316,8 @@ class RemoteService extends ServiceBase {
|
|
|
316
316
|
false,
|
|
317
317
|
getPBKDF2Salt,
|
|
318
318
|
encryptionAlgorithm,
|
|
319
|
-
connectionOptions.encryptInternalMetadata ?? false
|
|
319
|
+
connectionOptions.encryptInternalMetadata ?? false,
|
|
320
|
+
connectionOptions.acceptUnencryptedContent ?? false
|
|
320
321
|
);
|
|
321
322
|
}
|
|
322
323
|
} catch (ex) {
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
import { handlers } from "../lib/HandlerUtils.js";
|
|
13
13
|
import { ServiceBase } from "./ServiceBase.js";
|
|
14
14
|
import { createInstanceLogFunction } from "../lib/logUtils.js";
|
|
15
|
+
import { normaliseAcceptUnencryptedContent } from "../../common/models/setting.encryption.js";
|
|
15
16
|
import { isCloudantURI } from "../../pouchdb/utils_couchdb.js";
|
|
16
17
|
import { decryptString, encryptString } from "../../encryption/stringEncryption.js";
|
|
17
18
|
import { encryptWithEphemeralSalt, HKDF_SALTED_ENCRYPTED_PREFIX } from "octagonal-wheels/encryption/hkdf";
|
|
@@ -78,6 +79,7 @@ class SettingService extends ServiceBase {
|
|
|
78
79
|
* @param settings The settings to adjust.
|
|
79
80
|
*/
|
|
80
81
|
adjustSettings(settings) {
|
|
82
|
+
settings.acceptUnencryptedContent = normaliseAcceptUnencryptedContent(settings.acceptUnencryptedContent);
|
|
81
83
|
if (migrateLegacyRemoteConfigurationsInPlace(settings, (message) => {
|
|
82
84
|
this._log(message, LOG_LEVEL_NOTICE);
|
|
83
85
|
})) {
|
package/dist/settings.d.ts
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
export { DEFAULT_SETTINGS, NEW_VAULT_SETTINGS, P2P_DEFAULT_SETTINGS, SETTINGS_SCHEMA_DEFAULTS, createNewVaultSettings, } from "./common/models/setting.const.defaults.js";
|
|
7
7
|
export { PREFERRED_BASE, PREFERRED_JOURNAL_SYNC, PREFERRED_SETTING_CLOUDANT, PREFERRED_SETTING_SELF_HOSTED, } from "./common/models/setting.const.preferred.js";
|
|
8
8
|
export { CURRENT_SETTING_VERSION } from "./common/models/setting.const.js";
|
|
9
|
+
export { normaliseAcceptUnencryptedContent } from "./common/models/setting.encryption.js";
|
|
9
10
|
export { deriveIdKey, deriveOrImportIdKey, formatIdRecoveryCode, configuredIdKey, ID_DERIVATION_VERSION, ID_RECOVERY_CODE_PREFIX, } from "./common/idDerivation.js";
|
|
10
11
|
export { getPathNormalizationVersion, normalisePathForIdentity } from "./common/pathNormalization.js";
|
|
11
12
|
export type { PathNormalizationVersion, PathIdentitySettings } from "./common/models/setting.type.js";
|
|
@@ -13,5 +14,5 @@ export { prepareSettingsForLoad, SettingsMigrationReviewCodes, type PreparedSett
|
|
|
13
14
|
export { assessTweakCompatibility } from "./common/models/tweak.compatibility.js";
|
|
14
15
|
export type { TweakAssessment, TweakAssessmentEntry, TweakAssessmentRelation, TweakAssessmentValue, TweakTransition, TweakTransitionReason, } from "./common/models/tweak.compatibility.js";
|
|
15
16
|
export type { TweakReconstruction, TweakValues } from "./common/models/tweak.definition.js";
|
|
16
|
-
export type { ObsidianLiveSyncSettings, RemoteDBSettings, RemoteTypeSettings } from "./common/models/setting.type.js";
|
|
17
|
+
export type { EncryptionSettings, ObsidianLiveSyncSettings, RemoteDBSettings, RemoteTypeSettings, } from "./common/models/setting.type.js";
|
|
17
18
|
export { SETTINGS_PROPERTY_POLICY, SettingPolicies, createMarkdownSettings, mergeMarkdownSettings, type SettingPropertyPolicy, type MarkdownSettings, type CredentialFreeMarkdownSettings, type PersistedSettings, } from "./common/models/setting.policy.js";
|
package/dist/settings.js
CHANGED
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
PREFERRED_SETTING_SELF_HOSTED
|
|
13
13
|
} from "./common/models/setting.const.preferred.js";
|
|
14
14
|
import { CURRENT_SETTING_VERSION } from "./common/models/setting.const.js";
|
|
15
|
+
import { normaliseAcceptUnencryptedContent } from "./common/models/setting.encryption.js";
|
|
15
16
|
import {
|
|
16
17
|
deriveIdKey,
|
|
17
18
|
deriveOrImportIdKey,
|
|
@@ -56,6 +57,7 @@ export {
|
|
|
56
57
|
formatIdRecoveryCode,
|
|
57
58
|
getPathNormalizationVersion,
|
|
58
59
|
mergeMarkdownSettings,
|
|
60
|
+
normaliseAcceptUnencryptedContent,
|
|
59
61
|
normalisePathForIdentity,
|
|
60
62
|
prepareSettingsForLoad
|
|
61
63
|
};
|