@vrtmrz/livesync-commonlib 0.3.0 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/README.md +27 -4
  2. package/dist/API/DirectFileManipulatorV2.d.ts +1 -0
  3. package/dist/API/DirectFileManipulatorV2.js +6 -12
  4. package/dist/API/processSetting.d.ts +1 -0
  5. package/dist/common/models/setting.const.defaults.js +1 -0
  6. package/dist/common/models/setting.const.qr.js +1 -0
  7. package/dist/common/models/setting.policy.d.ts +4 -0
  8. package/dist/common/models/setting.policy.js +1 -0
  9. package/dist/common/models/setting.type.d.ts +2 -0
  10. package/dist/common/models/tweak.definition.d.ts +1 -0
  11. package/dist/common/pathNamespace.d.ts +4 -0
  12. package/dist/common/pathNamespace.js +10 -0
  13. package/dist/common/settingConstants.d.ts +1 -0
  14. package/dist/common/settingConstants.js +4 -0
  15. package/dist/platform/AmbiguousNormalisedPathError.d.ts +16 -0
  16. package/dist/platform/AmbiguousNormalisedPathError.js +21 -0
  17. package/dist/platform/StoragePathResolver.d.ts +15 -0
  18. package/dist/platform/StoragePathResolver.js +113 -0
  19. package/dist/platform/browser/UnicodeResolvingFileSystemAccessStorageAdapter.d.ts +74 -0
  20. package/dist/platform/browser/UnicodeResolvingFileSystemAccessStorageAdapter.js +169 -0
  21. package/dist/platform/browser/index.d.ts +1 -0
  22. package/dist/platform/browser/index.js +2 -0
  23. package/dist/platform/browser/storage.d.ts +23 -0
  24. package/dist/platform/browser/storage.js +138 -0
  25. package/dist/platform/node/UnicodeResolvingNodeStorageAdapter.d.ts +79 -0
  26. package/dist/platform/node/UnicodeResolvingNodeStorageAdapter.js +218 -0
  27. package/dist/platform/node/index.d.ts +1 -0
  28. package/dist/platform/node/index.js +2 -0
  29. package/dist/platform/node/storage.d.ts +30 -1
  30. package/dist/platform/node/storage.js +88 -0
  31. package/dist/platform/pathComparison.d.ts +53 -0
  32. package/dist/platform/pathComparison.js +39 -0
  33. package/dist/platform/pathTypes.d.ts +154 -0
  34. package/dist/platform/pathTypes.js +0 -0
  35. package/dist/platform/storagePathResolution.d.ts +13 -0
  36. package/dist/platform/storagePathResolution.js +9 -0
  37. package/dist/replication/SyncParamsHandler.d.ts +1 -0
  38. package/dist/replication/SyncParamsHandler.js +5 -1
  39. package/dist/replication/couchdb/LiveSyncReplicator.js +5 -3
  40. package/dist/replication/journal/JournalReceiveFailure.d.ts +7 -0
  41. package/dist/replication/journal/JournalReceiveFailure.js +16 -0
  42. package/dist/replication/journal/JournalSyncCore.d.ts +22 -3
  43. package/dist/replication/journal/JournalSyncCore.js +288 -166
  44. package/dist/replication/journal/JournalSyncTypes.d.ts +13 -0
  45. package/dist/replication/journal/LiveSyncJournalReplicator.d.ts +6 -1
  46. package/dist/replication/journal/LiveSyncJournalReplicator.js +31 -44
  47. package/dist/replication/journal/journalCompatibility.d.ts +9 -0
  48. package/dist/replication/journal/journalCompatibility.js +58 -0
  49. package/dist/replication/journal/journalReceive.d.ts +23 -0
  50. package/dist/replication/journal/journalReceive.js +44 -0
  51. package/dist/replication/journal/journalRecords.d.ts +10 -0
  52. package/dist/replication/journal/journalRecords.js +96 -0
  53. package/dist/replication/trystero/TrysteroReplicator.d.ts +2 -0
  54. package/dist/serviceModules/Rebuilder.js +2 -1
  55. package/dist/services/base/FileProcessingService.d.ts +2 -2
  56. package/dist/services/base/RemoteConnection.d.ts +2 -0
  57. package/dist/services/base/RemoteService.d.ts +1 -1
  58. package/dist/services/base/RemoteService.js +13 -5
  59. package/dist/services/implements/injectable/InjectableVaultService.d.ts +1 -1
  60. package/dist/services/lib/couchdbHttpCache.d.ts +5 -0
  61. package/dist/services/lib/couchdbHttpCache.js +36 -0
  62. package/dist/storage.d.ts +4 -0
  63. package/dist/storage.js +19 -0
  64. package/dist/string_and_binary/path.js +4 -7
  65. package/dist/worker/bgWorker.js +1 -1
  66. package/docs/adr/2026_11_shared_storage_path_resolution.md +75 -0
  67. package/docs/design_docs/storage_path_resolution.md +306 -0
  68. package/docs/development.md +11 -1
  69. package/docs/journal-receive-recovery.md +66 -0
  70. package/docs/platform-storage.md +61 -0
  71. package/docs/releasing.md +25 -0
  72. package/docs/unicode-path-identity.md +49 -17
  73. package/package.json +9 -1
@@ -59,15 +59,61 @@ class NodeStorageAdapter {
59
59
  return null;
60
60
  }
61
61
  }
62
+ /** Read metadata for an exact physical path, returning null only when it is absent. */
63
+ async statResolved(path) {
64
+ let stat;
65
+ try {
66
+ stat = await nodeFsPromises.stat(await this.resolvePath(path));
67
+ } catch (error) {
68
+ if (error.code === "ENOENT") return null;
69
+ throw error;
70
+ }
71
+ return {
72
+ size: stat.size,
73
+ mtime: Math.floor(stat.mtimeMs),
74
+ ctime: getNodeFileCreationTime(stat),
75
+ type: stat.isDirectory() ? "folder" : "file"
76
+ };
77
+ }
78
+ /** Enumerate immediate physical children, returning null only when the directory is absent. */
79
+ async readDirectory(path) {
80
+ let entries;
81
+ try {
82
+ entries = await nodeFsPromises.readdir(await this.resolvePath(path), { withFileTypes: true });
83
+ } catch (error) {
84
+ if (error.code === "ENOENT") return null;
85
+ throw error;
86
+ }
87
+ const directoryEntries = [];
88
+ for (const entry of entries) {
89
+ if (entry.isDirectory()) directoryEntries.push({ name: entry.name, kind: "directory" });
90
+ else if (entry.isFile()) directoryEntries.push({ name: entry.name, kind: "file" });
91
+ }
92
+ return directoryEntries;
93
+ }
62
94
  async stat(path) {
63
95
  return await this.trystat(path);
64
96
  }
65
97
  async mkdir(path) {
98
+ await this.mkdirPath(path);
99
+ }
100
+ /** Create an exact resolved directory path. */
101
+ async mkdirResolved(path) {
102
+ await this.mkdirPath(path);
103
+ }
104
+ async mkdirPath(path) {
66
105
  const fullPath = await this.resolvePath(path);
67
106
  await nodeFsPromises.mkdir(fullPath, { recursive: true });
68
107
  await this.assertNoSymbolicLinks(fullPath);
69
108
  }
70
109
  async remove(path) {
110
+ await this.removePath(path);
111
+ }
112
+ /** Remove an exact resolved file or directory path. */
113
+ async removeResolved(path) {
114
+ await this.removePath(path);
115
+ }
116
+ async removePath(path) {
71
117
  const fullPath = await this.resolvePath(path, false);
72
118
  const stat = await nodeFsPromises.stat(fullPath);
73
119
  if (stat.isDirectory()) {
@@ -77,6 +123,13 @@ class NodeStorageAdapter {
77
123
  }
78
124
  }
79
125
  async read(path) {
126
+ return await this.readPath(path);
127
+ }
128
+ /** Read a file by its exact resolved physical path. */
129
+ async readResolved(path) {
130
+ return await this.readPath(path);
131
+ }
132
+ async readPath(path) {
80
133
  const handle = await nodeFsPromises.open(
81
134
  await this.resolvePath(path, false),
82
135
  nodeFsConstants.O_RDONLY | NO_FOLLOW
@@ -88,6 +141,13 @@ class NodeStorageAdapter {
88
141
  }
89
142
  }
90
143
  async readBinary(path) {
144
+ return await this.readBinaryPath(path);
145
+ }
146
+ /** Read bytes by their exact resolved physical path. */
147
+ async readBinaryResolved(path) {
148
+ return await this.readBinaryPath(path);
149
+ }
150
+ async readBinaryPath(path) {
91
151
  const handle = await nodeFsPromises.open(
92
152
  await this.resolvePath(path, false),
93
153
  nodeFsConstants.O_RDONLY | NO_FOLLOW
@@ -100,22 +160,50 @@ class NodeStorageAdapter {
100
160
  }
101
161
  }
102
162
  async write(path, data, options) {
163
+ await this.writePath(path, data, options);
164
+ }
165
+ /** Write text to an exact resolved physical path. */
166
+ async writeResolved(path, data, options) {
167
+ await this.writePath(path, data, options);
168
+ }
169
+ async writePath(path, data, options) {
103
170
  const fullPath = await this.resolvePath(path, false);
104
171
  await nodeFsPromises.mkdir(nodePath.dirname(fullPath), { recursive: true });
105
172
  await this.writeFile(fullPath, data, options, false);
106
173
  }
107
174
  async writeBinary(path, data, options) {
175
+ await this.writeBinaryPath(path, data, options);
176
+ }
177
+ /** Write bytes to an exact resolved physical path. */
178
+ async writeBinaryResolved(path, data, options) {
179
+ await this.writeBinaryPath(path, data, options);
180
+ }
181
+ async writeBinaryPath(path, data, options) {
108
182
  const fullPath = await this.resolvePath(path, false);
109
183
  await nodeFsPromises.mkdir(nodePath.dirname(fullPath), { recursive: true });
110
184
  await this.writeFile(fullPath, new Uint8Array(data), options, false);
111
185
  }
112
186
  async append(path, data, options) {
187
+ await this.appendPath(path, data, options);
188
+ }
189
+ /** Append text to an exact resolved physical path. */
190
+ async appendResolved(path, data, options) {
191
+ await this.appendPath(path, data, options);
192
+ }
193
+ async appendPath(path, data, options) {
113
194
  const fullPath = await this.resolvePath(path, false);
114
195
  await nodeFsPromises.mkdir(nodePath.dirname(fullPath), { recursive: true });
115
196
  await this.writeFile(fullPath, data, options, true);
116
197
  }
117
198
  /** Atomically rename or move an entry without leaving the injected root. */
118
199
  async rename(sourcePath, targetPath) {
200
+ await this.renamePath(sourcePath, targetPath);
201
+ }
202
+ /** Rename or move exact resolved physical paths without leaving the injected root. */
203
+ async renameResolved(sourcePath, targetPath) {
204
+ await this.renamePath(sourcePath, targetPath);
205
+ }
206
+ async renamePath(sourcePath, targetPath) {
119
207
  const fullSourcePath = await this.resolvePath(sourcePath, false);
120
208
  const fullTargetPath = await this.resolvePath(targetPath, false);
121
209
  await nodeFsPromises.mkdir(nodePath.dirname(fullTargetPath), { recursive: true });
@@ -0,0 +1,53 @@
1
+ import type { DocumentPath, DocumentPathParts, FilePath, PathComparisonKey, PathComparisonSettings } from "./pathTypes.js";
2
+ /**
3
+ * Validate raw storage input without changing its spelling.
4
+ *
5
+ * @param path - A slash-separated path relative to the host-selected root.
6
+ * @returns The original path branded as `FilePath`; the empty path denotes the root.
7
+ * @throws Rejects absolute, drive-qualified, backslash, and traversal-segment input.
8
+ * @remarks Does not normalise Unicode, resolve physical names, or check existence.
9
+ */
10
+ export declare function parseFilePath(path: string): FilePath;
11
+ /**
12
+ * Mark an original document path before routing its Metadata namespace.
13
+ *
14
+ * @param path - Original document-path text, optionally including one namespace.
15
+ * @returns The same text branded as `DocumentPath`.
16
+ * @throws Rejects a non-string value.
17
+ * @remarks Storage validation follows namespace routing. This function does not
18
+ * recover original spelling from a comparison key or validate a physical path.
19
+ */
20
+ export declare function parseDocumentPath(path: string): DocumentPath;
21
+ /**
22
+ * Split one recognised Metadata namespace from an original document path.
23
+ *
24
+ * @param path - Original document path; a further colon remains in the file path.
25
+ * @returns The namespace, or an empty prefix, and the original remaining spelling.
26
+ * @remarks Does not validate the resulting file path for storage access.
27
+ */
28
+ export declare function splitDocumentPath(path: DocumentPath): DocumentPathParts;
29
+ /**
30
+ * Join a routed namespace and its original file path without normalising either.
31
+ *
32
+ * @param parts - One recognised namespace and an original file path.
33
+ * @returns Their concatenation as an original document path.
34
+ */
35
+ export declare function joinDocumentPath({ prefix, path }: DocumentPathParts): DocumentPath;
36
+ /**
37
+ * Derive an identity key for a file path within one storage root.
38
+ *
39
+ * @param path - Original file path without a Metadata namespace.
40
+ * @param settings - Explicit Unicode and case comparison settings.
41
+ * @returns A storage-domain comparison key; retain the original path for I/O.
42
+ * @throws Rejects an unsupported path normalisation version.
43
+ */
44
+ export declare function getStoragePathComparisonKey(path: FilePath, settings: PathComparisonSettings): PathComparisonKey<"storage">;
45
+ /**
46
+ * Derive a document identity key while preserving its Metadata namespace.
47
+ *
48
+ * @param path - Original document path, optionally including one namespace.
49
+ * @param settings - Explicit Unicode and case comparison settings for the body.
50
+ * @returns A document-domain key which distinguishes namespaces with equal bodies.
51
+ * @throws Rejects an unsupported path normalisation version.
52
+ */
53
+ export declare function getDocumentPathComparisonKey(path: DocumentPath, settings: PathComparisonSettings): PathComparisonKey<"document">;
@@ -0,0 +1,39 @@
1
+ import { normalisePathForIdentity } from "../common/pathNormalization.js";
2
+ import { splitPathNamespace } from "../common/pathNamespace.js";
3
+ import { validateStoragePath } from "./storagePath.js";
4
+ function parseFilePath(path) {
5
+ return validateStoragePath(path);
6
+ }
7
+ function parseDocumentPath(path) {
8
+ if (typeof path !== "string") throw new TypeError("A document path must be a string");
9
+ return path;
10
+ }
11
+ function splitDocumentPath(path) {
12
+ const [prefix, body] = splitPathNamespace(path);
13
+ return { prefix, path: body };
14
+ }
15
+ function joinDocumentPath({ prefix, path }) {
16
+ return prefix + path;
17
+ }
18
+ function normaliseFilePath(path) {
19
+ return normalisePathForIdentity(path, 1);
20
+ }
21
+ function comparisonPath(path, settings) {
22
+ const normalised = settings.pathNormalizationVersion === 1 ? normaliseFilePath(path) : normalisePathForIdentity(path, settings.pathNormalizationVersion);
23
+ return settings.handleFilenameCaseSensitive ? normalised : normalised.toLowerCase();
24
+ }
25
+ function getStoragePathComparisonKey(path, settings) {
26
+ return comparisonPath(path, settings);
27
+ }
28
+ function getDocumentPathComparisonKey(path, settings) {
29
+ const { prefix, path: body } = splitDocumentPath(path);
30
+ return prefix + comparisonPath(body, settings);
31
+ }
32
+ export {
33
+ getDocumentPathComparisonKey,
34
+ getStoragePathComparisonKey,
35
+ joinDocumentPath,
36
+ parseDocumentPath,
37
+ parseFilePath,
38
+ splitDocumentPath
39
+ };
@@ -0,0 +1,154 @@
1
+ import type { TaggedType } from "octagonal-wheels/common/types";
2
+ import type { FilePath, FilePathWithPrefix, FilePathWithPrefixLC } from "../common/models/db.type.js";
3
+ import type { PathNormalizationVersion } from "../common/models/setting.type.js";
4
+ import type { PathNamespace } from "../common/pathNamespace.js";
5
+ /**
6
+ * An original file path without a Metadata namespace.
7
+ *
8
+ * @remarks
9
+ * This compatibility type does not establish NFC form, physical spelling, or
10
+ * existence. Validate raw storage input with `parseFilePath`.
11
+ */
12
+ export type { FilePath };
13
+ /**
14
+ * An original document path with an optional recognised Metadata namespace.
15
+ *
16
+ * @remarks
17
+ * Excludes the legacy comparison-key variant. Route the namespace before
18
+ * validating the remaining file path for storage access.
19
+ */
20
+ export type DocumentPath = Exclude<FilePathWithPrefix, FilePathWithPrefixLC>;
21
+ declare const unicodeForm: unique symbol;
22
+ declare const storagePath: unique symbol;
23
+ /**
24
+ * A file path in Unicode NFC form, without case conversion.
25
+ *
26
+ * @remarks
27
+ * NFC form alone does not establish physical storage spelling or existence.
28
+ * This refinement is used within normalisation helpers and is not re-exported
29
+ * by the focused storage entry point.
30
+ */
31
+ export type NfcFilePath = FilePath & {
32
+ readonly [unicodeForm]: "NFC";
33
+ };
34
+ /**
35
+ * A root-relative storage target whose existing components use resolved spelling.
36
+ *
37
+ * @remarks
38
+ * Produced by resolution or supported physical enumeration. A write target may
39
+ * contain missing components; this type does not guarantee existence, entry
40
+ * kind, or protection against concurrent changes. The empty path denotes the
41
+ * root, subject to each operation's root rules.
42
+ */
43
+ export type StoragePath = FilePath & {
44
+ readonly [storagePath]: true;
45
+ };
46
+ /**
47
+ * A path identity key produced by the configured Unicode and case comparison.
48
+ *
49
+ * @typeParam Domain - `storage` compares within one storage root; `document`
50
+ * retains the Metadata namespace so different document kinds remain distinct.
51
+ *
52
+ * @remarks
53
+ * Retain the original path separately. A comparison key cannot establish an
54
+ * original filename and must not be passed to storage or namespace operations.
55
+ */
56
+ export type PathComparisonKey<Domain extends "storage" | "document"> = TaggedType<string, `PathComparisonKey:${Domain}`>;
57
+ /** Unicode and case settings used to derive path comparison keys. */
58
+ export type PathComparisonSettings = Readonly<{
59
+ /** `0` retains Legacy Unicode handling; `1` compares Unicode NFC forms. */
60
+ pathNormalizationVersion: PathNormalizationVersion;
61
+ /** Preserve letter case when true; otherwise apply the existing `toLowerCase()` rule. */
62
+ handleFilenameCaseSensitive: boolean;
63
+ }>;
64
+ /** The namespace and original file path obtained by splitting one document path. */
65
+ export type DocumentPathParts = Readonly<{
66
+ /** One recognised Metadata namespace, or the empty string for an ordinary file. */
67
+ prefix: PathNamespace;
68
+ /** Original spelling after removing that one namespace. */
69
+ path: FilePath;
70
+ }>;
71
+ /** One immediate physical child returned by a strict directory reader. */
72
+ export type DirectoryEntry = Readonly<{
73
+ /** Unmodified child name, rather than a relative path containing multiple components. */
74
+ name: string;
75
+ /** Entry kind reported by the storage host. */
76
+ kind: "file" | "directory";
77
+ }>;
78
+ /** A physical child path and its kind, ready for a storage scan to consume. */
79
+ export type StorageEntry = Readonly<{
80
+ /** Root-relative path retaining the directory listing's actual spelling. */
81
+ path: StoragePath;
82
+ /** Entry kind from the same directory listing. */
83
+ kind: DirectoryEntry["kind"];
84
+ }>;
85
+ /**
86
+ * Read a directory's complete immediate children using actual names and kinds.
87
+ *
88
+ * @param physicalDirectory - Resolved directory path relative to the host's root.
89
+ * @returns The children, including an empty array for an empty directory, or
90
+ * `null` only when the directory is absent.
91
+ * @throws Propagates permission, non-directory, and other I/O failures instead
92
+ * of reporting absence or a successful partial listing.
93
+ */
94
+ export type ReadDirectory = (physicalDirectory: StoragePath) => Promise<readonly DirectoryEntry[] | null>;
95
+ /** Resolved paths for a rename which the storage host has yet to perform. */
96
+ export type ResolvedRename = Readonly<{
97
+ /** Existing source spelling. */
98
+ source: StoragePath;
99
+ /** Resolved target, retaining a requested leaf spelling change where applicable. */
100
+ target: StoragePath;
101
+ }>;
102
+ /**
103
+ * Resolve NFC-equivalent names through strict directory reads under one policy.
104
+ *
105
+ * @remarks
106
+ * Operations reject ambiguous candidates even when an exact spelling exists,
107
+ * propagate reader failures, and perform no filesystem mutation. Resolution
108
+ * does not reserve a path against concurrent changes; hosts own that lifecycle.
109
+ */
110
+ export interface StoragePathResolver {
111
+ /**
112
+ * Resolve an existing file or directory using its physical spelling.
113
+ *
114
+ * @param path - Original path relative to the selected storage root.
115
+ * @returns The resolved path, or `null` when a component is absent.
116
+ */
117
+ resolveExisting(path: FilePath): Promise<StoragePath | null>;
118
+ /**
119
+ * Resolve a write target while preserving any missing suffix as requested.
120
+ *
121
+ * @param path - Original target path relative to the selected storage root.
122
+ * @returns The resolved target; this operation creates no missing entries.
123
+ */
124
+ resolveForWrite(path: FilePath): Promise<StoragePath>;
125
+ /**
126
+ * Resolve both sides of an explicit rename, including a leaf spelling change.
127
+ *
128
+ * @param source - Original source entry path; the root is not an entry.
129
+ * @param target - Requested target entry path; the root is not an entry.
130
+ * @returns Both paths, or `null` when the source is absent. The host retains
131
+ * responsibility for performing the rename and handling replacement.
132
+ */
133
+ resolveRename(source: FilePath, target: FilePath): Promise<ResolvedRename | null>;
134
+ /**
135
+ * Enumerate an already resolved directory without resolving each child again.
136
+ *
137
+ * @param path - Physical directory path relative to the selected root.
138
+ * @returns Child paths and kinds, or `null` when the directory is absent.
139
+ * @throws Rejects equivalent child names as ambiguous before returning a listing.
140
+ */
141
+ listResolvedDirectory(path: StoragePath): Promise<readonly StorageEntry[] | null>;
142
+ }
143
+ /** Dependencies and comparison policy for constructing an NFC path resolver. */
144
+ export type StoragePathResolverOptions = Readonly<{
145
+ /** Strict host enumeration; it must distinguish absence from I/O failure. */
146
+ readDirectory: ReadDirectory;
147
+ /** Policy copied at construction; construct a new resolver when settings change. */
148
+ policy: Readonly<{
149
+ /** The shared resolver accepts NFC mode only; Legacy hosts retain their existing paths. */
150
+ pathNormalizationVersion: 1;
151
+ /** Preserve letter case when true; otherwise compare using `toLowerCase()`. */
152
+ handleFilenameCaseSensitive: boolean;
153
+ }>;
154
+ }>;
File without changes
@@ -0,0 +1,13 @@
1
+ import type { StoragePathResolver as ResolverContract, StoragePathResolverOptions } from "./pathTypes.js";
2
+ export type { DirectoryEntry, ReadDirectory, ResolvedRename, StorageEntry, StoragePathResolver, StoragePathResolverOptions, } from "./pathTypes.js";
3
+ export { AmbiguousNormalisedPathError } from "./AmbiguousNormalisedPathError.js";
4
+ /**
5
+ * Bind strict directory reads to a copied NFC resolution policy.
6
+ *
7
+ * @param options - Host enumeration and explicit NFC/case settings.
8
+ * @returns A resolver which reads current listings without retaining a directory cache.
9
+ * @throws Rejects a path version other than `1` or a non-boolean case setting.
10
+ * @remarks Construction performs no I/O. Resolution performs no mutation or
11
+ * atomic reservation; construct a new resolver when its comparison settings change.
12
+ */
13
+ export declare function createStoragePathResolver(options: StoragePathResolverOptions): ResolverContract;
@@ -0,0 +1,9 @@
1
+ import { StoragePathResolver } from "./StoragePathResolver.js";
2
+ import { AmbiguousNormalisedPathError } from "./AmbiguousNormalisedPathError.js";
3
+ function createStoragePathResolver(options) {
4
+ return new StoragePathResolver(options);
5
+ }
6
+ export {
7
+ AmbiguousNormalisedPathError,
8
+ createStoragePathResolver
9
+ };
@@ -32,6 +32,7 @@ export declare class SyncParamsNotFoundError extends SyncParamsHandlerError {
32
32
  }
33
33
  export declare class SyncParamsUpdateError extends SyncParamsHandlerError {
34
34
  }
35
+ export declare function isSyncParamsError(error: unknown): error is SyncParamsFetchError | SyncParamsNotFoundError | SyncParamsUpdateError;
35
36
  /** Create a handler owned by one operation rather than the process-wide server cache. */
36
37
  export declare function createSyncParamsHandler({ put, get, create }: CreateSyncParamsHanderOptions): SyncParamsHandler;
37
38
  export {};
@@ -22,6 +22,9 @@ class SyncParamsNotFoundError extends SyncParamsHandlerError {
22
22
  }
23
23
  class SyncParamsUpdateError extends SyncParamsHandlerError {
24
24
  }
25
+ function isSyncParamsError(error) {
26
+ return error instanceof SyncParamsFetchError || error instanceof SyncParamsNotFoundError || error instanceof SyncParamsUpdateError;
27
+ }
25
28
  function createSyncParamsHandler({ put, get, create }) {
26
29
  let taskFetchParameters = void 0;
27
30
  const _fetchSyncParameters = async () => {
@@ -115,5 +118,6 @@ export {
115
118
  SyncParamsUpdateError,
116
119
  clearHandlers,
117
120
  createSyncParamsHanderForServer,
118
- createSyncParamsHandler
121
+ createSyncParamsHandler,
122
+ isSyncParamsError
119
123
  };
@@ -169,7 +169,8 @@ class LiveSyncCouchDBReplicator extends LiveSyncAbstractReplicator {
169
169
  value.enableCompression,
170
170
  value.pathNormalizationVersion,
171
171
  value.readChunksOnline,
172
- value.useRequestAPI
172
+ value.useRequestAPI,
173
+ value.useCouchDBCacheControlHeadersOnly === true
173
174
  ]);
174
175
  const binding = identity(snapshot);
175
176
  let connection;
@@ -721,7 +722,7 @@ ${sendingDocs}/(${sentDocsCount} done)`,
721
722
  if (cancellationRequested()) {
722
723
  return false;
723
724
  }
724
- if (await this.ensurePBKDF2Salt(setting, showResult, !retrying) === false || cancellationRequested()) {
725
+ if (await this.ensurePBKDF2Salt(setting, showResult, false) === false || cancellationRequested()) {
725
726
  return false;
726
727
  }
727
728
  if (this.controller) {
@@ -1442,7 +1443,8 @@ ${sendingDocs}/(${sentDocsCount} done)`,
1442
1443
  {
1443
1444
  ...connectionOptions,
1444
1445
  encryptionAlgorithm: settings.E2EEAlgorithm,
1445
- encryptInternalMetadata: usesEncryptedInternalMetadata(settings)
1446
+ encryptInternalMetadata: usesEncryptedInternalMetadata(settings),
1447
+ useCouchDBCacheControlHeadersOnly: settings.useCouchDBCacheControlHeadersOnly === true
1446
1448
  }
1447
1449
  );
1448
1450
  }
@@ -0,0 +1,7 @@
1
+ import type { JournalReceiveFailureStage } from "./JournalSyncTypes.js";
2
+ export declare class JournalReceiveFailure extends Error {
3
+ readonly stage: JournalReceiveFailureStage;
4
+ readonly key?: string;
5
+ constructor(stage: JournalReceiveFailureStage, key?: string);
6
+ }
7
+ export declare function isJournalReceiveFailure(error: unknown): error is JournalReceiveFailure;
@@ -0,0 +1,16 @@
1
+ class JournalReceiveFailure extends Error {
2
+ constructor(stage, key) {
3
+ super("Journal receive failed at " + stage);
4
+ this.stage = stage;
5
+ this.key = key;
6
+ }
7
+ stage;
8
+ key;
9
+ }
10
+ function isJournalReceiveFailure(error) {
11
+ return error instanceof JournalReceiveFailure;
12
+ }
13
+ export {
14
+ JournalReceiveFailure,
15
+ isJournalReceiveFailure
16
+ };
@@ -1,10 +1,10 @@
1
1
  import { type EntryDoc, type SyncParameters, type BucketSyncSetting, type RemoteDBSettings } from "../../common/types.js";
2
2
  import type { ReplicationCallback, ReplicationStat } from "../LiveSyncAbstractReplicator.js";
3
3
  import { type SimpleStore } from "../../common/utils.js";
4
- import { type CheckPointInfo } from "./JournalSyncTypes.js";
4
+ import { type CheckPointInfo, type StoppedJournal } from "./JournalSyncTypes.js";
5
5
  import type { LiveSyncJournalReplicatorEnv } from "./LiveSyncJournalReplicatorEnv.js";
6
6
  import { type IJournalStorage, type JournalStorageConditionalWriteResult, type JournalStorageReadResult } from "./objectstore/JournalStorageAdapter.js";
7
- type ProcessingEntry = PouchDB.Core.PutDocument<EntryDoc> & PouchDB.Core.GetMeta;
7
+ import { type ProcessingEntry } from "./journalRecords.js";
8
8
  export declare class JournalSyncCore {
9
9
  _settings: BucketSyncSetting;
10
10
  storage: IJournalStorage;
@@ -17,6 +17,19 @@ export declare class JournalSyncCore {
17
17
  store: SimpleStore<CheckPointInfo>;
18
18
  requestedStop: boolean;
19
19
  private syncParamsHandler?;
20
+ private receiveTask?;
21
+ private stoppedJournal?;
22
+ private checkpointGeneration;
23
+ private receiveConfiguration;
24
+ private matchesStoppedContext;
25
+ /** Return the current failure for presentation before an explicit single-Journal skip. */
26
+ getStoppedJournal(): StoppedJournal | undefined;
27
+ /**
28
+ * Acknowledge only the exact failure presented to the user, then resume receipt.
29
+ * Stale snapshots, another active receive, and a later Stop request are rejected.
30
+ * Any subsequent Journal failure stops the resumed operation normally.
31
+ */
32
+ skipStoppedJournalAndResume(stopped: StoppedJournal, showMessage?: boolean): Promise<boolean>;
20
33
  getInitialSyncParameters(): Promise<SyncParameters>;
21
34
  getSyncParameters(): Promise<SyncParameters>;
22
35
  putSyncParameters(params: SyncParameters): Promise<boolean>;
@@ -65,13 +78,19 @@ export declare class JournalSyncCore {
65
78
  hasRemoteJournals(): Promise<boolean>;
66
79
  _getRemoteJournals(): Promise<string[]>;
67
80
  processDocuments(allDocs: ProcessingEntry[]): Promise<boolean>;
81
+ private processDocumentsForReceive;
68
82
  private _createReceiveReadableStream;
69
83
  private _createReceiveTransformStream;
70
84
  private _createReceiveWritableStream;
85
+ /** Receive until completion, a failure, or an explicit Stop request. */
71
86
  receiveRemoteJournal(showMessage?: boolean): Promise<boolean>;
87
+ private startReceive;
88
+ private prepareStoppedJournalSkip;
89
+ private recordReceiveFailure;
90
+ private receiveJournalFiles;
91
+ private performReceive;
72
92
  sync(showResult?: boolean): Promise<boolean>;
73
93
  requestStop(): void;
74
94
  /** Stop this Journal operation owner and release its storage transport. */
75
95
  dispose(): void;
76
96
  }
77
- export {};