@vrtmrz/livesync-commonlib 0.5.0 → 0.6.0
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/dist/common/LSError.d.ts +13 -0
- package/dist/common/LSError.js +19 -1
- package/dist/diagnostics/local.d.ts +7 -2
- package/dist/interfaces/DatabaseFileAccess.d.ts +20 -4
- package/dist/interfaces/FileHandler.d.ts +67 -1
- package/dist/interfaces/FileHandler.js +16 -0
- package/dist/interfaces/StorageEventManager.d.ts +7 -0
- package/dist/managers/ChunkFetcher.d.ts +16 -0
- package/dist/managers/ChunkFetcher.js +190 -112
- package/dist/managers/EntryManager/EntryManager.d.ts +7 -0
- package/dist/managers/EntryManager/EntryManager.js +6 -0
- package/dist/managers/EntryManager/EntryManagerImpls.d.ts +9 -5
- package/dist/managers/EntryManager/EntryManagerImpls.js +103 -76
- package/dist/managers/LayeredChunkManager/ArrivalWaitLayer.d.ts +7 -3
- package/dist/managers/LayeredChunkManager/ArrivalWaitLayer.js +83 -16
- package/dist/managers/LayeredChunkManager/DatabaseReadLayer.d.ts +3 -2
- package/dist/managers/LayeredChunkManager/DatabaseReadLayer.js +38 -36
- package/dist/managers/LayeredChunkManager/types.d.ts +15 -1
- package/dist/managers/LayeredChunkManager.d.ts +4 -0
- package/dist/managers/LayeredChunkManager.js +19 -6
- package/dist/managers/LiveSyncManagers.d.ts +2 -0
- package/dist/managers/LiveSyncManagers.js +6 -0
- package/dist/managers/StorageEventManager.d.ts +22 -0
- package/dist/managers/StorageEventManager.js +48 -1
- package/dist/pouchdb/LiveSyncLocalDB.d.ts +32 -0
- package/dist/pouchdb/LiveSyncLocalDB.js +72 -18
- package/dist/pouchdb/LocalDatabaseReadScope.d.ts +24 -0
- package/dist/pouchdb/LocalDatabaseReadScope.js +62 -0
- package/dist/pouchdb/pathIdentityCompatibility.d.ts +6 -2
- package/dist/pouchdb/pathIdentityCompatibility.js +15 -10
- package/dist/replication/contentRead.d.ts +3 -0
- package/dist/replication/contentRead.js +4 -0
- package/dist/replication/couchdb/LiveSyncReplicator.d.ts +8 -1
- package/dist/replication/couchdb/LiveSyncReplicator.js +187 -119
- package/dist/replication/index.d.ts +5 -1
- package/dist/replication/index.js +18 -1
- package/dist/serviceFeatures/offlineScanner/files.d.ts +1 -1
- package/dist/serviceFeatures/offlineScanner/files.js +27 -7
- package/dist/serviceFeatures/offlineScanner/scan.d.ts +5 -1
- package/dist/serviceFeatures/offlineScanner/scan.js +2 -1
- package/dist/serviceFeatures/offlineScanner.d.ts +1 -1
- package/dist/serviceFeatures/offlineScanner.js +10 -2
- package/dist/serviceModules/ServiceDatabaseFileAccessBase.d.ts +13 -0
- package/dist/serviceModules/ServiceDatabaseFileAccessBase.js +190 -123
- package/dist/serviceModules/ServiceFileHandlerBase/deletion.js +17 -7
- package/dist/serviceModules/ServiceFileHandlerBase/events.d.ts +3 -2
- package/dist/serviceModules/ServiceFileHandlerBase/events.js +9 -9
- package/dist/serviceModules/ServiceFileHandlerBase/protection.js +24 -9
- package/dist/serviceModules/ServiceFileHandlerBase/provenance.d.ts +10 -0
- package/dist/serviceModules/ServiceFileHandlerBase/provenance.js +28 -4
- package/dist/serviceModules/ServiceFileHandlerBase/reflection.d.ts +11 -5
- package/dist/serviceModules/ServiceFileHandlerBase/reflection.js +144 -58
- package/dist/serviceModules/ServiceFileHandlerBase/saving.js +16 -2
- package/dist/serviceModules/ServiceFileHandlerBase/scanning.js +1 -0
- package/dist/serviceModules/ServiceFileHandlerBase.d.ts +7 -2
- package/dist/serviceModules/ServiceFileHandlerBase.js +13 -4
- package/dist/services/base/ControlService.js +1 -5
- package/dist/services/base/DatabaseEventService.d.ts +3 -0
- package/dist/services/base/DatabaseEventService.js +3 -0
- package/dist/services/base/DatabaseService.d.ts +15 -0
- package/dist/services/base/DatabaseService.js +85 -4
- package/dist/services/base/IService.d.ts +18 -1
- package/dist/services/base/KeyValueDBService.d.ts +5 -4
- package/dist/services/base/KeyValueDBService.js +46 -48
- package/dist/services/base/ReplicationService.d.ts +3 -1
- package/dist/services/base/ReplicationService.js +3 -1
- package/dist/services/base/VaultScanResult.d.ts +5 -0
- package/dist/services/lib/HandlerUtils.d.ts +40 -5
- package/dist/services/lib/HandlerUtils.js +52 -4
- package/docs/development.md +8 -0
- package/docs/offline-scanner.md +46 -0
- package/docs/releasing.md +42 -0
- package/package.json +1 -1
package/dist/common/LSError.d.ts
CHANGED
|
@@ -45,4 +45,17 @@ export declare class LiveSyncError extends Error implements ErrorWithCause {
|
|
|
45
45
|
}
|
|
46
46
|
export declare class LiveSyncFatalError extends LiveSyncError {
|
|
47
47
|
}
|
|
48
|
+
/** A request failed at a known remote boundary, retaining its native unknown cause. */
|
|
49
|
+
export declare class RemoteRequestError extends Error {
|
|
50
|
+
name: string;
|
|
51
|
+
constructor(message?: string, options?: {
|
|
52
|
+
cause?: unknown;
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
/** Terminal content failure, carrying only directly observed resource facts. */
|
|
56
|
+
export declare class ContentReadError extends Error {
|
|
57
|
+
readonly failure: import("../interfaces/DatabaseFileAccess.js").ContentReadFailure;
|
|
58
|
+
readonly name = "ContentReadError";
|
|
59
|
+
constructor(failure: import("../interfaces/DatabaseFileAccess.js").ContentReadFailure);
|
|
60
|
+
}
|
|
48
61
|
export {};
|
package/dist/common/LSError.js
CHANGED
|
@@ -106,7 +106,25 @@ class LiveSyncError extends Error {
|
|
|
106
106
|
}
|
|
107
107
|
class LiveSyncFatalError extends LiveSyncError {
|
|
108
108
|
}
|
|
109
|
+
class RemoteRequestError extends Error {
|
|
110
|
+
name = "RemoteRequestError";
|
|
111
|
+
constructor(message, options) {
|
|
112
|
+
super(message, options);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
class ContentReadError extends Error {
|
|
116
|
+
constructor(failure) {
|
|
117
|
+
super(`Could not read content for ${failure.documentId}${failure.revision ? ` (${failure.revision})` : ""}`, {
|
|
118
|
+
cause: failure.cause
|
|
119
|
+
});
|
|
120
|
+
this.failure = failure;
|
|
121
|
+
}
|
|
122
|
+
failure;
|
|
123
|
+
name = "ContentReadError";
|
|
124
|
+
}
|
|
109
125
|
export {
|
|
126
|
+
ContentReadError,
|
|
110
127
|
LiveSyncError,
|
|
111
|
-
LiveSyncFatalError
|
|
128
|
+
LiveSyncFatalError,
|
|
129
|
+
RemoteRequestError
|
|
112
130
|
};
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import type { EntryDoc } from "../common/types.js";
|
|
2
2
|
import type { DiagnosticDatabaseSource } from "./types.js";
|
|
3
|
-
/**
|
|
4
|
-
|
|
3
|
+
/** Promise reads used by local diagnostics; a host can supply its owned read boundary. */
|
|
4
|
+
type LocalDiagnosticDatabase = Pick<DiagnosticDatabaseSource, "info" | "get"> & {
|
|
5
|
+
allDocs(options: PouchDB.Core.AllDocsOptions & Partial<Pick<PouchDB.Core.AllDocsWithinRangeOptions, "startkey">>): Promise<PouchDB.Core.AllDocsResponse<EntryDoc>>;
|
|
6
|
+
};
|
|
7
|
+
/** Wrap local Promise reads without taking ownership or using chunk caches. */
|
|
8
|
+
export declare function createLocalDiagnosticSource(database: LocalDiagnosticDatabase): DiagnosticDatabaseSource;
|
|
9
|
+
export {};
|
|
@@ -1,5 +1,21 @@
|
|
|
1
|
-
import type { FilePathWithPrefix, LoadedEntry, MetaEntry, UXFileInfo, UXFileInfoStub } from "../common/types.js";
|
|
1
|
+
import type { DocumentID, FilePathWithPrefix, LoadedEntry, MetaEntry, UXFileInfo, UXFileInfoStub } from "../common/types.js";
|
|
2
|
+
export type ContentReadResource = "local-database" | "remote";
|
|
3
|
+
/** Known recovery dependencies; unresolved or invalid content has no automatic retry dependency. */
|
|
4
|
+
export interface ContentReadFailure {
|
|
5
|
+
documentId: DocumentID;
|
|
6
|
+
revision?: string;
|
|
7
|
+
/** Every listed dependency must recover; an empty list requires manual review. */
|
|
8
|
+
resources: readonly ContentReadResource[];
|
|
9
|
+
/** Original runtime diagnostics, which must not be persisted or inspected to choose recovery. */
|
|
10
|
+
cause: unknown;
|
|
11
|
+
}
|
|
2
12
|
export interface DatabaseFileAccess {
|
|
13
|
+
/** Strict reads preserve ordinary absence but reject failed I/O or incomplete content. */
|
|
14
|
+
readEntryMeta: DatabaseFileAccess["fetchEntryMeta"];
|
|
15
|
+
readEntryFromMeta: DatabaseFileAccess["fetchEntryFromMeta"];
|
|
16
|
+
readEntry: DatabaseFileAccess["fetchEntry"];
|
|
17
|
+
readConflictedRevs: DatabaseFileAccess["getConflictedRevs"];
|
|
18
|
+
readLiveContentRevisions: DatabaseFileAccess["findLiveContentRevisions"];
|
|
3
19
|
delete: (file: UXFileInfoStub | FilePathWithPrefix, rev?: string) => Promise<boolean>;
|
|
4
20
|
store: (file: UXFileInfo, force?: boolean, skipCheck?: boolean) => Promise<boolean>;
|
|
5
21
|
/**
|
|
@@ -43,12 +59,12 @@ export interface DatabaseFileAccess {
|
|
|
43
59
|
* available Chunks, without requesting remote data or waiting for missing Chunks to arrive.
|
|
44
60
|
*
|
|
45
61
|
* A unique match can recover provenance; several matches avoid a duplicate write but leave
|
|
46
|
-
* its origin ambiguous. An empty result means no match was confirmed
|
|
47
|
-
*
|
|
62
|
+
* its origin ambiguous. An empty result means no match was confirmed. The strict read rejects
|
|
63
|
+
* failed I/O; this compatibility facade returns no matches on failure. This read neither records provenance nor reserves a leaf for a later write.
|
|
48
64
|
*/
|
|
49
65
|
findLiveContentRevisions: (file: UXFileInfoStub | FilePathWithPrefix, content: string | string[] | Blob | ArrayBuffer) => Promise<string[]>;
|
|
50
66
|
fetch: (file: UXFileInfoStub | FilePathWithPrefix, rev?: string, waitForReady?: boolean, skipCheck?: boolean) => Promise<UXFileInfo | false>;
|
|
51
|
-
fetchEntryFromMeta: (meta: MetaEntry, waitForReady?: boolean, skipCheck?: boolean) => Promise<LoadedEntry | false>;
|
|
67
|
+
fetchEntryFromMeta: (meta: MetaEntry, waitForReady?: boolean, skipCheck?: boolean, localOnly?: boolean) => Promise<LoadedEntry | false>;
|
|
52
68
|
fetchEntryMeta: (file: UXFileInfoStub | FilePathWithPrefix, rev?: string, skipCheck?: boolean) => Promise<MetaEntry | false>;
|
|
53
69
|
/**
|
|
54
70
|
* Load a revision's content, or return `false` when it cannot be loaded.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { FilePath, FilePathWithPrefix, MetaEntry } from "../common/models/db.type.js";
|
|
1
|
+
import type { DocumentID, FilePath, FilePathWithPrefix, MetaEntry } from "../common/models/db.type.js";
|
|
2
2
|
import type { UXFileInfo, UXFileInfoStub, UXInternalFileInfoStub } from "../common/models/fileaccess.type.js";
|
|
3
3
|
export interface StoreFileOptions {
|
|
4
4
|
/** Recheck storage and provenance, with bounded retries for recovery scans. */
|
|
@@ -43,7 +43,71 @@ export interface DeletionRecoveryClearedResult extends DeletionRecoveryDiagnosti
|
|
|
43
43
|
* file may require user reconciliation; automatic convergence is not guaranteed.
|
|
44
44
|
*/
|
|
45
45
|
export type DeletionRecoveryResult = DeletionRecoveryUnchangedResult | DeletionRecoveryCleanupPendingResult | DeletionRecoveryRemovalUnconfirmedResult | DeletionRecoveryClearedResult;
|
|
46
|
+
export interface ReflectionTarget {
|
|
47
|
+
documentId: DocumentID;
|
|
48
|
+
revision: string;
|
|
49
|
+
}
|
|
50
|
+
/** Premises supplied by the target owner; no failure state is retained here. */
|
|
51
|
+
export interface ReflectionOperationContext {
|
|
52
|
+
readonly target: ReflectionTarget;
|
|
53
|
+
readonly source: "scan" | "received";
|
|
54
|
+
/** The owner may return false or throw its own scope-cancellation value. */
|
|
55
|
+
readonly checkpoint?: () => boolean | void;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* A normal outcome of one file reflection attempt; terminal failures reject.
|
|
59
|
+
*
|
|
60
|
+
* @remarks Only `completed` permits completion bookkeeping. `policy` is an
|
|
61
|
+
* intentional skip under the applicable reflection policy, and `cancelled`
|
|
62
|
+
* means the target owner declined continuation at a checkpoint. Neither outcome
|
|
63
|
+
* establishes completed reflection or grants an automatic retry.
|
|
64
|
+
*/
|
|
65
|
+
export type FileReflectionResult = Readonly<{
|
|
66
|
+
status: "completed" | "policy" | "cancelled";
|
|
67
|
+
}>;
|
|
68
|
+
/**
|
|
69
|
+
* Reflection completed, including an already-matching file or an already-absent deletion.
|
|
70
|
+
* @remarks Callers may perform completion bookkeeping; a new storage write is not required.
|
|
71
|
+
*/
|
|
72
|
+
export declare const FILE_REFLECTION_COMPLETED: Readonly<{
|
|
73
|
+
status: "completed";
|
|
74
|
+
}>;
|
|
75
|
+
/**
|
|
76
|
+
* Applicable policy intentionally withheld ordinary file reflection.
|
|
77
|
+
*
|
|
78
|
+
* @remarks Examples include handing a conflict to its resolution workflow,
|
|
79
|
+
* preserving unsynchronised storage as a conflict, an existing folder at the
|
|
80
|
+
* target path, or a host which does not apply received files automatically.
|
|
81
|
+
* Protection or conflict scheduling may already have occurred. This is a
|
|
82
|
+
* normal policy decision, not a failed read or a promise of a later retry.
|
|
83
|
+
*/
|
|
84
|
+
export declare const FILE_REFLECTION_POLICY: Readonly<{
|
|
85
|
+
status: "policy";
|
|
86
|
+
}>;
|
|
87
|
+
/**
|
|
88
|
+
* The target owner's checkpoint declined continuation of this reflection attempt.
|
|
89
|
+
* @remarks This does not convert unrelated I/O failures into cancellation or roll back earlier work.
|
|
90
|
+
*/
|
|
91
|
+
export declare const FILE_REFLECTION_CANCELLED: Readonly<{
|
|
92
|
+
status: "cancelled";
|
|
93
|
+
}>;
|
|
94
|
+
/**
|
|
95
|
+
* Test whether reflection permits the caller's completion bookkeeping.
|
|
96
|
+
* @param result - The normal outcome returned by the reflection operation.
|
|
97
|
+
* @returns True only for `completed`, including completion without a new write.
|
|
98
|
+
*/
|
|
99
|
+
export declare function isReflectionCompleted(result: FileReflectionResult): boolean;
|
|
100
|
+
/**
|
|
101
|
+
* Test whether the target owner declined continuation at a checkpoint.
|
|
102
|
+
* @param result - The normal outcome returned by the reflection operation.
|
|
103
|
+
* @returns True only for `cancelled`; false can also mean a normal policy skip.
|
|
104
|
+
* @remarks Legacy Boolean facades can preserve cancellation with this predicate.
|
|
105
|
+
* Callers which require completed reflection must use {@link isReflectionCompleted}.
|
|
106
|
+
*/
|
|
107
|
+
export declare function isReflectionCancelled(result: FileReflectionResult): boolean;
|
|
46
108
|
export interface IFileHandler {
|
|
109
|
+
/** Strict reflection; failures reject to the target owner. */
|
|
110
|
+
reflectDatabaseEntry(entry: MetaEntry, info: UXFileInfoStub | UXFileInfo | FilePath | null, force?: boolean, operation?: ReflectionOperationContext): Promise<FileReflectionResult>;
|
|
47
111
|
readFileFromStub(file: UXFileInfoStub | UXFileInfo): Promise<UXFileInfo>;
|
|
48
112
|
/**
|
|
49
113
|
* Record an untracked, unchanged file during an equal-time scan.
|
|
@@ -53,6 +117,8 @@ export interface IFileHandler {
|
|
|
53
117
|
tryRecordUntrackedFileRevision(info: UXFileInfoStub | UXFileInfo, expectedRevision: string): Promise<boolean>;
|
|
54
118
|
/** Metadata-only scan hint; never certifies content equality or changes provenance. */
|
|
55
119
|
canSkipUnchangedFile?(info: UXFileInfoStub, expected: MetaEntry): Promise<boolean>;
|
|
120
|
+
/** Confirm current bytes and recorded revision without a remote content read. */
|
|
121
|
+
inspectCurrentFileProvenance?(path: FilePathWithPrefix, revision: string): Promise<boolean>;
|
|
56
122
|
/**
|
|
57
123
|
* Report whether complete provenance-key discovery is configured.
|
|
58
124
|
* @returns A composition capability, rather than a store-readiness or health check.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const FILE_REFLECTION_COMPLETED = Object.freeze({ status: "completed" });
|
|
2
|
+
const FILE_REFLECTION_POLICY = Object.freeze({ status: "policy" });
|
|
3
|
+
const FILE_REFLECTION_CANCELLED = Object.freeze({ status: "cancelled" });
|
|
4
|
+
function isReflectionCompleted(result) {
|
|
5
|
+
return result.status === "completed";
|
|
6
|
+
}
|
|
7
|
+
function isReflectionCancelled(result) {
|
|
8
|
+
return result.status === "cancelled";
|
|
9
|
+
}
|
|
10
|
+
export {
|
|
11
|
+
FILE_REFLECTION_CANCELLED,
|
|
12
|
+
FILE_REFLECTION_COMPLETED,
|
|
13
|
+
FILE_REFLECTION_POLICY,
|
|
14
|
+
isReflectionCancelled,
|
|
15
|
+
isReflectionCompleted
|
|
16
|
+
};
|
|
@@ -14,6 +14,13 @@ export declare abstract class StorageEventManager {
|
|
|
14
14
|
/** Compatibility hosts without an ownership view must retain content checks. */
|
|
15
15
|
hasPendingFileEvent?(_filename: FilePath): boolean;
|
|
16
16
|
abstract waitForIdle(): Promise<void>;
|
|
17
|
+
/**
|
|
18
|
+
* Pause new file-handler dispatch when the manager supports a reversible pause.
|
|
19
|
+
* @returns A promise fulfilled after processing active at the call settles; pending work is not awaited.
|
|
20
|
+
*/
|
|
21
|
+
pauseDispatch?(): Promise<void>;
|
|
22
|
+
/** Resume file-handler dispatch after a supported pause. */
|
|
23
|
+
resumeDispatch?(): void;
|
|
17
24
|
abstract restoreState(): Promise<void>;
|
|
18
25
|
/**
|
|
19
26
|
* Complete accepted work before its storage closes. Custom hosts must stop
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import { type DocumentID } from "../common/types.js";
|
|
2
2
|
import { type ChunkManager } from "./ChunkManager.js";
|
|
3
3
|
import type { ChunkFetchSource } from "./chunkFetchSource.js";
|
|
4
|
+
import type { LogFunction } from "../services/lib/logUtils.js";
|
|
4
5
|
import type { IReplicatorService, ISettingService } from "../services/base/IService.js";
|
|
5
6
|
export declare const EVENT_MISSING_CHUNKS = "missingChunks";
|
|
6
7
|
export declare const EVENT_MISSING_CHUNK_REMOTE = "missingChunkRemote";
|
|
7
8
|
export declare const EVENT_CHUNK_FETCHED = "chunkFetched";
|
|
9
|
+
export declare const EVENT_CHUNK_FAILED = "chunkFailed";
|
|
8
10
|
export type ChunkFetcherOptions = {
|
|
11
|
+
/** Host-owned logger; standalone instances default to the global logger. */
|
|
12
|
+
log?: LogFunction;
|
|
9
13
|
settingService: ISettingService;
|
|
10
14
|
chunkManager: ChunkManager;
|
|
11
15
|
replicatorService: IReplicatorService;
|
|
@@ -15,6 +19,7 @@ export type ChunkFetcherOptions = {
|
|
|
15
19
|
};
|
|
16
20
|
export declare class ChunkFetcher {
|
|
17
21
|
options: ChunkFetcherOptions;
|
|
22
|
+
private readonly log;
|
|
18
23
|
get chunkManager(): ChunkManager;
|
|
19
24
|
queue: DocumentID[];
|
|
20
25
|
private readonly pendingClaims;
|
|
@@ -44,6 +49,8 @@ export declare class ChunkFetcher {
|
|
|
44
49
|
private touchClaims;
|
|
45
50
|
private waitForActivityBoundary;
|
|
46
51
|
private waitBeforeRemoteRequest;
|
|
52
|
+
/** Return the remaining delay, or reserve the request start synchronously. */
|
|
53
|
+
private reserveRequestInterval;
|
|
47
54
|
private resolveLocallyAvailableRetries;
|
|
48
55
|
private logFetchedChunks;
|
|
49
56
|
private applyMissingChunkResults;
|
|
@@ -60,4 +67,13 @@ export declare class ChunkFetcher {
|
|
|
60
67
|
canRequestMore(): boolean;
|
|
61
68
|
private isReady;
|
|
62
69
|
requestMissingChunks(): Promise<void>;
|
|
70
|
+
private admitRequestBatch;
|
|
71
|
+
private cleanupRequestBatch;
|
|
72
|
+
private fetchRemoteChunks;
|
|
73
|
+
private fetchWithRemoteError;
|
|
74
|
+
private acceptFetchedChunks;
|
|
75
|
+
private storeFetchedChunks;
|
|
76
|
+
private publishAcceptedChunks;
|
|
77
|
+
private publishUnsupportedReplicatorResult;
|
|
78
|
+
private publishRequestFailure;
|
|
63
79
|
}
|