@vrtmrz/livesync-commonlib 0.6.0 → 0.6.1

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.
@@ -9,6 +9,7 @@ import {
9
9
  IDPrefixes
10
10
  } from "../common/types.js";
11
11
  import { isEncryptedChunkEntry, isSyncInfoEntry, isObfuscatedEntry } from "../common/utils.js";
12
+ import { UnsupportedEncryptedDocumentFormatError } from "../replication/UnsupportedEncryptedDocumentFormatError.js";
12
13
  import {
13
14
  UnencryptedContentRejectedError
14
15
  } from "../replication/UnencryptedContentRejectedError.js";
@@ -101,7 +102,7 @@ function assertUnencryptedContentPolicy(doc, algorithm, acceptUnencryptedContent
101
102
  for (const contentKind of contentKinds) {
102
103
  if (contentKind !== "eden" && record.e_ === true) {
103
104
  if (forceV1DecryptsMarkedData || dataIsHandledByExistingDecryptor) continue;
104
- throw new Error("Encrypted file content uses a representation which this E2EE reader cannot decrypt.");
105
+ throw new UnsupportedEncryptedDocumentFormatError();
105
106
  }
106
107
  if (contentKind === "chunk" && algorithm === E2EEAlgorithms.ForceV1 && !record.e_ && isEncryptedChunkEntry(doc) && hasForceV1CiphertextHeader) {
107
108
  continue;
@@ -0,0 +1,13 @@
1
+ /** Raised when the reader has no decoding route for a document marked as encrypted. */
2
+ export declare class UnsupportedEncryptedDocumentFormatError extends Error {
3
+ readonly name = "UnsupportedEncryptedDocumentFormatError";
4
+ constructor(options?: {
5
+ cause?: unknown;
6
+ });
7
+ /**
8
+ * Finds the rejection in a cause chain. PouchDB copies the error's own
9
+ * properties into a different error type. Recover the class from its name
10
+ * and keep the reported exception as the cause for diagnostics.
11
+ */
12
+ static findIn(error: unknown): UnsupportedEncryptedDocumentFormatError | undefined;
13
+ }
@@ -0,0 +1,28 @@
1
+ const UNSUPPORTED_FORMAT_ERROR_NAME = "UnsupportedEncryptedDocumentFormatError";
2
+ class UnsupportedEncryptedDocumentFormatError extends Error {
3
+ name = UNSUPPORTED_FORMAT_ERROR_NAME;
4
+ constructor(options) {
5
+ super("Encrypted file content uses a representation which this E2EE reader cannot decrypt.", options);
6
+ }
7
+ /**
8
+ * Finds the rejection in a cause chain. PouchDB copies the error's own
9
+ * properties into a different error type. Recover the class from its name
10
+ * and keep the reported exception as the cause for diagnostics.
11
+ */
12
+ static findIn(error) {
13
+ const seen = /* @__PURE__ */ new Set();
14
+ let current = error;
15
+ while (typeof current === "object" && current !== null && !seen.has(current)) {
16
+ if (current instanceof UnsupportedEncryptedDocumentFormatError) return current;
17
+ if (current instanceof Error && current.name === UNSUPPORTED_FORMAT_ERROR_NAME) {
18
+ return new UnsupportedEncryptedDocumentFormatError({ cause: current });
19
+ }
20
+ seen.add(current);
21
+ current = "cause" in current ? current.cause : void 0;
22
+ }
23
+ return void 0;
24
+ }
25
+ }
26
+ export {
27
+ UnsupportedEncryptedDocumentFormatError
28
+ };
@@ -1,4 +1,5 @@
1
1
  import type { LiveSyncLocalDB } from "../../pouchdb/LiveSyncLocalDB.js";
2
+ import { UnsupportedEncryptedDocumentFormatError } from "../UnsupportedEncryptedDocumentFormatError.js";
2
3
  import type { ReplicationStatics } from "../../common/models/shared.definition.js";
3
4
  import { type EntryDoc, type RemoteDBSettings, type EntryLeaf, type SyncParameters, type DatabaseEntry, type NodeData, type RemotePreferredTweakResult } from "../../common/types.js";
4
5
  import type { InitialFetchFastForwardResource } from "../RemoteResource.js";
@@ -9,6 +10,7 @@ import { type CentralCompatibilityDecisionRecorder } from "../CentralCompatibili
9
10
  import { type ReplicationOutcome } from "../ReplicatorProvider.js";
10
11
  import { type ForgetJoinedDeviceResult, type JoinedDevicesSnapshot } from "../joinedDevices.js";
11
12
  export type { OwnedCouchDBConnection, RemoteConnectionOpenOptions } from "../../services/base/RemoteConnection.js";
13
+ type SyncProcessingResult = "DONE" | "NEED_RETRY" | "NEED_RESURRECT" | "FAILED" | "CANCELLED" | UnsupportedEncryptedDocumentFormatError;
12
14
  /**
13
15
  * Compatibility constructor environment for the CouchDB Replicator facade.
14
16
  *
@@ -89,7 +91,7 @@ export declare class LiveSyncCouchDBReplicator extends LiveSyncAbstractReplicato
89
91
  private readLocalDatabase;
90
92
  replicationErrored(e: unknown, database?: LiveSyncLocalDB | null): void;
91
93
  replicationPaused(): void;
92
- processSync(syncHandler: PouchDB.Replication.Sync<EntryDoc> | PouchDB.Replication.Replication<EntryDoc>, showResult: boolean, docSentOnStart: number, docArrivedOnStart: number, syncMode: "sync" | "pullOnly" | "pushOnly", retrying: boolean, reportCancelledAsDone?: boolean): Promise<"DONE" | "NEED_RETRY" | "NEED_RESURRECT" | "FAILED" | "CANCELLED">;
94
+ processSync(syncHandler: PouchDB.Replication.Sync<EntryDoc> | PouchDB.Replication.Replication<EntryDoc>, showResult: boolean, docSentOnStart: number, docArrivedOnStart: number, syncMode: "sync" | "pullOnly" | "pushOnly", retrying: boolean, reportCancelledAsDone?: boolean): Promise<SyncProcessingResult>;
93
95
  getEmptyMaxEntry(remoteID: number): {
94
96
  _id: string;
95
97
  maxSeq: number | string;
@@ -3,6 +3,7 @@ import {
3
3
  getUnencryptedContentRejection,
4
4
  isUnencryptedContentRejectedError
5
5
  } from "../UnencryptedContentRejectedError.js";
6
+ import { UnsupportedEncryptedDocumentFormatError } from "../UnsupportedEncryptedDocumentFormatError.js";
6
7
  import { observeReplicationProgress } from "./replicationProgress.js";
7
8
  import {
8
9
  VER,
@@ -101,7 +102,8 @@ async function* genReplication(s, signal, log) {
101
102
  const requestSource = s.pull ?? s;
102
103
  let policyFailureReported = false;
103
104
  const onRequestError = (error) => {
104
- if (policyFailureReported || !isUnencryptedContentRejectedError(error)) return;
105
+ if (policyFailureReported) return;
106
+ if (!isUnencryptedContentRejectedError(error) && !UnsupportedEncryptedDocumentFormatError.findIn(error)) return;
105
107
  policyFailureReported = true;
106
108
  push(["error", error]);
107
109
  };
@@ -328,6 +330,9 @@ class LiveSyncCouchDBReplicator extends LiveSyncAbstractReplicator {
328
330
  if (result === ONE_SHOT_REPLICATION_ALREADY_RUNNING) {
329
331
  return replicationBlocked("replication-in-progress");
330
332
  }
333
+ if (result instanceof UnsupportedEncryptedDocumentFormatError) {
334
+ return replicationFailed(result);
335
+ }
331
336
  return outcomeFromFiniteOpenReplication(result, centralCompatibilityRecoveryHint(decision));
332
337
  } catch (error) {
333
338
  return replicationFailed(error, centralCompatibilityRecoveryHint(decision));
@@ -420,7 +425,9 @@ class LiveSyncCouchDBReplicator extends LiveSyncAbstractReplicator {
420
425
  }
421
426
  return;
422
427
  }
423
- this.requestCurrentDatabaseInspection(e, database);
428
+ if (!(e instanceof UnsupportedEncryptedDocumentFormatError)) {
429
+ this.requestCurrentDatabaseInspection(e, database);
430
+ }
424
431
  this.log("Replication error", LOG_LEVEL_NOTICE, "sync");
425
432
  this.log(e, LOG_LEVEL_VERBOSE);
426
433
  }
@@ -501,8 +508,10 @@ class LiveSyncCouchDBReplicator extends LiveSyncAbstractReplicator {
501
508
  case "denied":
502
509
  this.replicationDenied(e);
503
510
  return "FAILED";
504
- case "error":
505
- this.replicationErrored(e, databaseOwner);
511
+ case "error": {
512
+ const unsupportedFormat = UnsupportedEncryptedDocumentFormatError.findIn(e);
513
+ this.replicationErrored(unsupportedFormat ?? e, databaseOwner);
514
+ if (unsupportedFormat) return unsupportedFormat;
506
515
  if (isUnencryptedContentRejectedError(e)) return "FAILED";
507
516
  this.log("Replication stopped.", showResult ? LOG_LEVEL_NOTICE : LOG_LEVEL_INFO, "sync");
508
517
  if (this.env.services.remote.hadLastPostFailedBySize) {
@@ -519,6 +528,7 @@ class LiveSyncCouchDBReplicator extends LiveSyncAbstractReplicator {
519
528
  this.log(e, LOG_LEVEL_VERBOSE);
520
529
  }
521
530
  return "FAILED";
531
+ }
522
532
  case "paused":
523
533
  this.replicationPaused();
524
534
  break;
@@ -533,9 +543,10 @@ class LiveSyncCouchDBReplicator extends LiveSyncAbstractReplicator {
533
543
  }
534
544
  return "CANCELLED";
535
545
  } catch (ex) {
536
- if (isUnencryptedContentRejectedError(ex)) {
537
- this.replicationErrored(ex, databaseOwner);
538
- return "FAILED";
546
+ const unsupportedFormat = UnsupportedEncryptedDocumentFormatError.findIn(ex);
547
+ if (unsupportedFormat || isUnencryptedContentRejectedError(ex)) {
548
+ this.replicationErrored(unsupportedFormat ?? ex, databaseOwner);
549
+ return unsupportedFormat ?? "FAILED";
539
550
  }
540
551
  this.requestCurrentDatabaseInspection(ex, databaseOwner);
541
552
  this.log(`Unexpected synchronization exception`);
@@ -766,7 +777,7 @@ ${sendingDocs}/(${sentDocsCount} done)`,
766
777
  recordCompatibilityDecision,
767
778
  cancellationRequested
768
779
  );
769
- return result === ONE_SHOT_REPLICATION_ALREADY_RUNNING ? false : result;
780
+ return result === true;
770
781
  }
771
782
  /**
772
783
  * Run one finite CouchDB transfer and close its owned remote connection.
@@ -873,10 +884,10 @@ ${sendingDocs}/(${sentDocsCount} done)`,
873
884
  }
874
885
  return true;
875
886
  }
876
- if (syncResult == "CANCELLED") {
877
- return false;
887
+ if (syncResult instanceof UnsupportedEncryptedDocumentFormatError) {
888
+ return syncResult;
878
889
  }
879
- if (syncResult == "FAILED") {
890
+ if (syncResult == "CANCELLED" || syncResult == "FAILED") {
880
891
  return false;
881
892
  }
882
893
  if (syncResult == "NEED_RESURRECT") {
@@ -934,10 +945,7 @@ ${sendingDocs}/(${sentDocsCount} done)`,
934
945
  if (!ownsSharedAttempt) {
935
946
  return ONE_SHOT_REPLICATION_ALREADY_RUNNING;
936
947
  }
937
- if (typeof next === "boolean") {
938
- return next;
939
- }
940
- return await next();
948
+ return typeof next === "function" ? await next() : next;
941
949
  }
942
950
  async checkOneShotReplicationConnectivity(setting, skipCheck, showResult, ignoreCleanLock, recordCompatibilityDecision) {
943
951
  if (setting.useRequestAPI) {
@@ -6,6 +6,7 @@ export { FILE_REFLECTION_COMPLETED, FILE_REFLECTION_POLICY, FILE_REFLECTION_CANC
6
6
  export type { FileReflectionResult, ReflectionTarget, ReflectionOperationContext, } from "../interfaces/FileHandler.js";
7
7
  export { isUnencryptedContentRejectedError, UnencryptedContentRejectedError, } from "./UnencryptedContentRejectedError.js";
8
8
  export type { UnencryptedContentKind } from "./UnencryptedContentRejectedError.js";
9
+ export { UnsupportedEncryptedDocumentFormatError } from "./UnsupportedEncryptedDocumentFormatError.js";
9
10
  export type { ActiveReplicatorContext, CapabilitySupport, ContinuousReplicationRequest, ContinuousReplicationTrigger, ContinuousRunner, InteractionAuthority, InteractionPermissions, NotApplicableCapability, NotImplementedCapability, NoInteraction, PermittedInteractionPermissions, ReplicationBlockReason, ReplicationAttemptFailure, ReplicationCancelled, ReplicationCompleted, ReplicationFailed, ReplicationInteraction, ReplicationOutcome, ReplicationProgressPresentation, ReplicationReadinessRequirements, ReplicationPartial, ReplicationFailureRequest, ReplicatorConfigurationIdentity, ReplicatorProviderDefinition, ReplicatorProviderDefinitionMap, StopActiveTransferRunner, SupportedCapability, UnattendedOneShotRequest, UnattendedReplicationTrigger, UnattendedOneShotRunner, UserInitiatedOneShotRequest, UserInitiatedReplicationAuthority, UserInitiatedOneShotRunner, } from "./ReplicatorProvider.js";
10
11
  export { CAPABILITY_SUPPORT_KINDS, CAPABILITY_UNAVAILABLE_REASONS } from "./ProviderCapability.js";
11
12
  export { NO_REMOTE_RESOURCE_CAPABILITIES, REMOTE_RESOURCE_KINDS } from "./RemoteResource.js";
@@ -33,6 +33,7 @@ import {
33
33
  isUnencryptedContentRejectedError,
34
34
  UnencryptedContentRejectedError
35
35
  } from "./UnencryptedContentRejectedError.js";
36
+ import { UnsupportedEncryptedDocumentFormatError } from "./UnsupportedEncryptedDocumentFormatError.js";
36
37
  import { CAPABILITY_SUPPORT_KINDS, CAPABILITY_UNAVAILABLE_REASONS } from "./ProviderCapability.js";
37
38
  import { NO_REMOTE_RESOURCE_CAPABILITIES, REMOTE_RESOURCE_KINDS } from "./RemoteResource.js";
38
39
  import {
@@ -84,6 +85,7 @@ export {
84
85
  REPLICATION_PROGRESS_PRESENTATIONS,
85
86
  USER_INITIATED_REPLICATION_AUTHORITY,
86
87
  UnencryptedContentRejectedError,
88
+ UnsupportedEncryptedDocumentFormatError,
87
89
  applyCentralRemoteAdministrationMutation,
88
90
  assessRemoteFeatureDocument,
89
91
  centralRemoteAdministrationVerificationFailed,
@@ -137,6 +137,7 @@ export declare abstract class ReplicationService<T extends ServiceContext = Serv
137
137
  *
138
138
  * This concrete maintenance entry point is intentionally absent from `IReplicationService`;
139
139
  * it is not a general application-readiness bypass.
140
+ * @throws {UnsupportedEncryptedDocumentFormatError} When the remote format prevents the download.
140
141
  */
141
142
  replicateAllFromRemoteForRebuild(showingNotice?: boolean): Promise<boolean>;
142
143
  private getActiveReplicatorFor;
@@ -1,3 +1,4 @@
1
+ import { UnsupportedEncryptedDocumentFormatError } from "../../replication/UnsupportedEncryptedDocumentFormatError.js";
1
2
  import {
2
3
  LOG_LEVEL_INFO,
3
4
  LOG_LEVEL_NOTICE,
@@ -356,6 +357,9 @@ class ReplicationService extends ServiceBase {
356
357
  expectedContext ??= context;
357
358
  return runDirectionalReplication(context, attemptSetting, direction, showingNotice);
358
359
  });
360
+ if (direction === DIRECTIONAL_REPLICATION.DOWNLOAD && admission === DIRECTIONAL_REPLICATION_ADMISSION.EXPLICIT_REBUILD && admitted?.status === "failed" && admitted.error instanceof UnsupportedEncryptedDocumentFormatError) {
361
+ throw admitted.error;
362
+ }
359
363
  if (admitted) return admitted;
360
364
  this._log(`Active replicator not found during directional ${direction}`, LOG_LEVEL_NOTICE);
361
365
  return replicationBlocked("no-active-replicator");
@@ -399,6 +403,7 @@ class ReplicationService extends ServiceBase {
399
403
  *
400
404
  * This concrete maintenance entry point is intentionally absent from `IReplicationService`;
401
405
  * it is not a general application-readiness bypass.
406
+ * @throws {UnsupportedEncryptedDocumentFormatError} When the remote format prevents the download.
402
407
  */
403
408
  async replicateAllFromRemoteForRebuild(showingNotice = false) {
404
409
  if (!this.databaseService.isDatabaseReady()) {
@@ -2,7 +2,7 @@
2
2
  date: 2026-10-26
3
3
  commonlib-version: "0.2.1"
4
4
  self-hosted-livesync-version: "1.0.40"
5
- status: unreleased
5
+ status: published
6
6
  ---
7
7
 
8
8
  # Full offline scan
@@ -13,7 +13,12 @@ Metadata inspection and repair, last-seen persistence, file collection and
13
13
  reflection, and scan orchestration. The entry module retains lifecycle integration
14
14
  and re-exports its existing public functions; callers do not need to change imports.
15
15
 
16
- Implementation note: the settings-controlled strict comparison correction for [Self-hosted LiveSync #1329](https://github.com/vrtmrz/obsidian-livesync/issues/1329) is implemented but unreleased. The original reviewed-version fields above retain their historical baseline.
16
+ Publication note: this contract, including host recovery integration, is available
17
+ in [Commonlib 0.6.0](https://github.com/vrtmrz/livesync-commonlib/releases/tag/0.6.0).
18
+ The reviewed-version fields above retain their historical baseline. Downstream adoption and runtime evidence are tracked separately in
19
+ [maintained-host evidence](proven-in-use.md).
20
+
21
+ Implementation note: the settings-controlled strict comparison correction for [Self-hosted LiveSync #1329](https://github.com/vrtmrz/obsidian-livesync/issues/1329) is available in Commonlib 0.6.0.
17
22
 
18
23
  This document defines the developer contract for `synchroniseAllFilesBetweenDBandStorage`. It describes how the scanner classifies each selected path, chooses an action, and records a database-to-storage reflection. Host-specific setup dialogue and recovery choices remain outside this contract.
19
24
 
@@ -76,7 +81,7 @@ The standard-file revalidation contract is:
76
81
 
77
82
  An inability to inspect the current path is not proof of absence. Revalidation suppresses a destructive half when storage inspection fails, records the failure, and leaves the operation pending. The full scan can still examine the current state and reports any selected-pair failure under its strict or explicitly partial completion policy. Target-file policy and file-size limits are evaluated from current settings rather than inherited from the saved event.
78
83
 
79
- The unreleased rename-exclusion guard retains `renameTarget` when a rename is converted to deletion during target filtering. Unlike an ordinary deletion, this intent can remove a file from synchronisation without removing it from storage. The guard distinguishes deliberate exclusion from transient case-collision rejection, preserves a recreated source, and permits a deliberately excluded same-ID destination without requiring that destination to disappear. Older snapshots without this optional field retain the absence-only rule. See [Storage events and database-to-storage reflection](storage-events-and-reflection.md) for the exact admission conditions and the separate ordinary watcher boundary.
84
+ The rename-exclusion guard retains `renameTarget` when a rename is converted to deletion during target filtering. Unlike an ordinary deletion, this intent can remove a file from synchronisation without removing it from storage. The guard distinguishes deliberate exclusion from transient case-collision rejection, preserves a recreated source, and permits a deliberately excluded same-ID destination without requiring that destination to disappear. Older snapshots without this optional field retain the absence-only rule. See [Storage events and database-to-storage reflection](storage-events-and-reflection.md) for the exact admission conditions and the separate ordinary watcher boundary.
80
85
 
81
86
  Independent validation of rename halves does not remove target-first execution. When the new path currently exists, its inclusion must finish successfully before the old-path deletion may run. A failed inclusion preserves the old database entry. When the new path is currently absent, there is no inclusion to publish, and a separately validated absence at the old path may be applied as deletion intent.
82
87
 
@@ -203,10 +208,13 @@ concurrency, and cost contracts. This opt-in extension is published in
203
208
  [Commonlib 0.4.2](https://github.com/vrtmrz/livesync-commonlib/releases/tag/0.4.2).
204
209
 
205
210
 
206
- ## Unreleased host recovery integration
211
+ <a id="unreleased-host-recovery-integration"></a>
212
+
213
+ ## Host recovery integration
207
214
 
208
- The following extension was reviewed against Commonlib 0.5.0 and Self-hosted
209
- LiveSync 1.0.50. It is implemented on the working branch and is not yet published.
215
+ The following extension was initially reviewed against Commonlib 0.5.0 and
216
+ Self-hosted LiveSync 1.0.50. It is published in
217
+ [Commonlib 0.6.0](https://github.com/vrtmrz/livesync-commonlib/releases/tag/0.6.0).
210
218
 
211
219
  `VaultScanOptions.onReflectionFailed(target, error)` receives a terminal ordinary DB-to-Vault reflection failure. The target is the selected input document ID and revision; a content error can separately identify the historical revision which could not be read. The scanner awaits the owner callback once. A callback rejection propagates as a persistence failure and is not converted into another content failure. Completed reflection, normal absence, and policy skips do not create failed work.
212
220
 
package/docs/releasing.md CHANGED
@@ -81,10 +81,11 @@ source compatibility changes use the next minor version under the policy.
81
81
 
82
82
  ### 0.6.0 integration changes
83
83
 
84
- Version 0.6.0 is an unreleased candidate with source compatibility changes to
85
- strict reads, file reflection, and database lifecycle integration. The standard
86
- base implementations supply the new members. Custom overrides must also follow
87
- the updated return and failure contracts.
84
+ Version [0.6.0](https://github.com/vrtmrz/livesync-commonlib/releases/tag/0.6.0)
85
+ introduces source compatibility changes to strict reads, file reflection, and
86
+ database lifecycle integration. The standard base implementations supply the new
87
+ members. Custom overrides must also follow the updated return and failure
88
+ contracts.
88
89
 
89
90
  Direct interface implementations must provide these additional members:
90
91
 
@@ -118,7 +119,7 @@ I/O can continue after its caller wait ends. Raw replication, changes-feed, and
118
119
  maintenance integrations retain responsibility for their own completion and lifetime.
119
120
 
120
121
  See [Local database lifecycle](database-lifecycle.md) and
121
- [Strict content reads and reflection](offline-scanner.md#unreleased-host-recovery-integration)
122
+ [Strict content reads and reflection](offline-scanner.md#host-recovery-integration)
122
123
  for operation ownership and host integration.
123
124
 
124
125
  ## Preparing a release
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vrtmrz/livesync-commonlib",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
4
4
  "description": "Shared data, storage, and replication primitives for Self-hosted LiveSync clients.",
5
5
  "type": "module",
6
6
  "types": "./dist/index.d.ts",