@vrtmrz/livesync-commonlib 0.4.0 → 0.4.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.
- package/dist/common/models/fileaccess.definition.d.ts +35 -0
- package/dist/common/models/fileaccess.definition.js +11 -0
- package/dist/common/typeUtils.d.ts +27 -4
- package/dist/interfaces/FileHandler.d.ts +1 -1
- package/dist/managers/StorageEventManager/admission.d.ts +50 -0
- package/dist/managers/StorageEventManager/admission.js +129 -0
- package/dist/managers/StorageEventManager/batching.d.ts +93 -0
- package/dist/managers/StorageEventManager/batching.js +97 -0
- package/dist/managers/StorageEventManager/operations.d.ts +142 -0
- package/dist/managers/StorageEventManager/operations.js +69 -0
- package/dist/managers/StorageEventManager/processing.d.ts +63 -0
- package/dist/managers/StorageEventManager/processing.js +94 -0
- package/dist/managers/StorageEventManager/queue.d.ts +73 -0
- package/dist/managers/StorageEventManager/queue.js +113 -0
- package/dist/managers/StorageEventManager/retry.d.ts +33 -0
- package/dist/managers/StorageEventManager/retry.js +31 -0
- package/dist/managers/StorageEventManager/snapshot.d.ts +46 -0
- package/dist/managers/StorageEventManager/snapshot.js +53 -0
- package/dist/managers/StorageEventManager/state.d.ts +155 -0
- package/dist/managers/StorageEventManager/state.js +105 -0
- package/dist/managers/StorageEventManager/watching.d.ts +93 -0
- package/dist/managers/StorageEventManager/watching.js +36 -0
- package/dist/managers/StorageEventManager.d.ts +303 -83
- package/dist/managers/StorageEventManager.js +457 -547
- package/dist/serviceModules/ServiceFileHandlerBase/chunks.d.ts +10 -0
- package/dist/serviceModules/ServiceFileHandlerBase/chunks.js +51 -0
- package/dist/serviceModules/ServiceFileHandlerBase/context.d.ts +168 -0
- package/dist/serviceModules/ServiceFileHandlerBase/context.js +15 -0
- package/dist/serviceModules/ServiceFileHandlerBase/deletion.d.ts +40 -0
- package/dist/serviceModules/ServiceFileHandlerBase/deletion.js +142 -0
- package/dist/serviceModules/ServiceFileHandlerBase/events.d.ts +20 -0
- package/dist/serviceModules/ServiceFileHandlerBase/events.js +205 -0
- package/dist/serviceModules/ServiceFileHandlerBase/locking.d.ts +23 -0
- package/dist/serviceModules/ServiceFileHandlerBase/locking.js +51 -0
- package/dist/serviceModules/ServiceFileHandlerBase/protection.d.ts +26 -0
- package/dist/serviceModules/ServiceFileHandlerBase/protection.js +67 -0
- package/dist/serviceModules/ServiceFileHandlerBase/provenance.d.ts +174 -0
- package/dist/serviceModules/ServiceFileHandlerBase/provenance.js +182 -0
- package/dist/serviceModules/ServiceFileHandlerBase/reflection.d.ts +48 -0
- package/dist/serviceModules/ServiceFileHandlerBase/reflection.js +344 -0
- package/dist/serviceModules/ServiceFileHandlerBase/renaming.d.ts +23 -0
- package/dist/serviceModules/ServiceFileHandlerBase/renaming.js +77 -0
- package/dist/serviceModules/ServiceFileHandlerBase/saving.d.ts +40 -0
- package/dist/serviceModules/ServiceFileHandlerBase/saving.js +306 -0
- package/dist/serviceModules/ServiceFileHandlerBase/scanning.d.ts +22 -0
- package/dist/serviceModules/ServiceFileHandlerBase/scanning.js +93 -0
- package/dist/serviceModules/ServiceFileHandlerBase/selection.d.ts +58 -0
- package/dist/serviceModules/ServiceFileHandlerBase/selection.js +94 -0
- package/dist/serviceModules/ServiceFileHandlerBase/storage.d.ts +55 -0
- package/dist/serviceModules/ServiceFileHandlerBase/storage.js +37 -0
- package/dist/serviceModules/ServiceFileHandlerBase.d.ts +119 -182
- package/dist/serviceModules/ServiceFileHandlerBase.js +182 -1402
- package/docs/conflict-resolution.md +3 -1
- package/docs/development.md +36 -0
- package/docs/offline-scanner.md +5 -1
- package/docs/p2p-transport-lifecycle.md +8 -1
- package/docs/storage-events-and-reflection.md +203 -19
- package/package.json +1 -1
|
@@ -1,29 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Compose host adapters with storage-event admission, batching, snapshotting, and processing.
|
|
3
|
+
* The facade keeps host services and protected extension hooks at the runtime boundary.
|
|
4
|
+
*/
|
|
5
|
+
import { type FileEventItem, type FilePath, type UXFileInfoStub, type UXFolderInfo, type UXInternalFileInfoStub } from "../common/types.js";
|
|
4
6
|
import type { IStorageAccessManager } from "../interfaces/StorageAccess.js";
|
|
5
|
-
import { type PromiseWithResolvers } from "octagonal-wheels/promises";
|
|
6
7
|
import { StorageEventManager, type FileEvent } from "../interfaces/StorageEventManager.js";
|
|
7
8
|
import type { IAPIService, IVaultService } from "../services/base/IService.js";
|
|
8
9
|
import type { SettingService } from "../services/base/SettingService.js";
|
|
9
10
|
import type { FileProcessingService } from "../services/base/FileProcessingService.js";
|
|
10
|
-
import {
|
|
11
|
+
import { type LogFunction } from "../services/lib/logUtils.js";
|
|
11
12
|
import type { IStorageEventManagerAdapter } from "./adapters/index.js";
|
|
12
|
-
type WaitInfo
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
declare const TYPE_SENTINEL_FLUSH = "SENTINEL_FLUSH";
|
|
20
|
-
type FileEventItemSentinelFlush = {
|
|
21
|
-
type: typeof TYPE_SENTINEL_FLUSH;
|
|
22
|
-
};
|
|
23
|
-
export type FileEventItemSentinel = FileEventItemSentinelFlush;
|
|
24
|
-
type RunQueuedEventsOptions = {
|
|
25
|
-
waitForProcessing?: boolean;
|
|
26
|
-
};
|
|
13
|
+
import { type WaitInfo } from "./StorageEventManager/batching.js";
|
|
14
|
+
import { type FileEventItemSentinel, type QueuedFileEvent, type RunQueuedEventsOptions } from "./StorageEventManager/state.js";
|
|
15
|
+
export type { FileEventItemSentinel } from "./StorageEventManager/state.js";
|
|
16
|
+
/**
|
|
17
|
+
* Bundle host services used to construct the platform-neutral storage-event manager.
|
|
18
|
+
* @remarks These dependencies keep vault access, file processing, settings, and diagnostics at the adapter boundary.
|
|
19
|
+
*/
|
|
27
20
|
export interface StorageEventManagerBaseDependencies {
|
|
28
21
|
setting: SettingService;
|
|
29
22
|
vaultService: IVaultService;
|
|
@@ -32,125 +25,352 @@ export interface StorageEventManagerBaseDependencies {
|
|
|
32
25
|
APIService: IAPIService;
|
|
33
26
|
}
|
|
34
27
|
/**
|
|
35
|
-
*
|
|
28
|
+
* Extract the host file type from a candidate adapter type.
|
|
29
|
+
* @typeParam T - The candidate adapter type.
|
|
30
|
+
* @remarks The conditional type resolves to `never` for non-adapter inputs; this is a compile-time type result, separate from any runtime type-guard outcome.
|
|
36
31
|
*/
|
|
37
|
-
export type ExtractFile<T> = T extends IStorageEventManagerAdapter<infer F,
|
|
32
|
+
export type ExtractFile<T> = T extends IStorageEventManagerAdapter<infer F, infer _Folder> ? F : never;
|
|
38
33
|
/**
|
|
39
|
-
*
|
|
34
|
+
* Extract the host folder type from a candidate adapter type.
|
|
35
|
+
* @typeParam T - The candidate adapter type.
|
|
36
|
+
* @remarks The conditional type resolves to `never` for non-adapter inputs; this is a compile-time type result, separate from any runtime type-guard outcome.
|
|
40
37
|
*/
|
|
41
|
-
export type ExtractFolder<T> = T extends IStorageEventManagerAdapter<
|
|
38
|
+
export type ExtractFolder<T> = T extends IStorageEventManagerAdapter<infer _File, infer D> ? D : never;
|
|
42
39
|
/**
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
40
|
+
* Compose a host adapter with the stateful storage-event pipeline.
|
|
41
|
+
* @typeParam TAdapter - The platform adapter which defines host file and folder representations.
|
|
42
|
+
* @remarks
|
|
43
|
+
* Public methods implement admission, flushing, restoration, and watcher lifecycle contracts.
|
|
44
|
+
* Protected getters, processing hooks, and watcher callbacks are extension points for host subclasses.
|
|
45
|
+
* Watcher callbacks remain protected so platform overrides continue to run while their base implementations share conversion through `forwardVaultEvent`.
|
|
46
|
+
* Private methods and effect objects are internal composition details of this facade.
|
|
47
47
|
*/
|
|
48
|
-
export declare abstract class StorageEventManagerBase<TAdapter extends IStorageEventManagerAdapter<
|
|
49
|
-
_log:
|
|
48
|
+
export declare abstract class StorageEventManagerBase<TAdapter extends IStorageEventManagerAdapter<unknown, unknown>> extends StorageEventManager {
|
|
49
|
+
_log: LogFunction;
|
|
50
50
|
protected setting: SettingService;
|
|
51
51
|
protected vaultService: IVaultService;
|
|
52
52
|
protected fileProcessing: FileProcessingService;
|
|
53
53
|
protected storageAccess: IStorageAccessManager;
|
|
54
54
|
protected adapter: TAdapter;
|
|
55
|
+
protected bufferedQueuedItems: QueuedFileEvent[];
|
|
56
|
+
protected concurrentProcessing: import("octagonal-wheels/concurrency/semaphore").SemaphoreObject;
|
|
57
|
+
protected _waitingMap: Map<string, WaitInfo>;
|
|
58
|
+
protected processingCount: number;
|
|
59
|
+
private readonly eventState;
|
|
60
|
+
private readonly buffer;
|
|
61
|
+
private readonly notifications;
|
|
62
|
+
private readonly log;
|
|
63
|
+
private readonly batching;
|
|
64
|
+
private readonly retry;
|
|
65
|
+
private readonly snapshotIO;
|
|
66
|
+
private readonly queue;
|
|
67
|
+
private readonly admission;
|
|
68
|
+
private readonly attempts;
|
|
69
|
+
private readonly handler;
|
|
70
|
+
/** Preserve adapter receivers and virtual admission when forwarding watcher notifications. */
|
|
71
|
+
private readonly watching;
|
|
72
|
+
/**
|
|
73
|
+
* Bind the platform adapter and host services to this manager instance.
|
|
74
|
+
* @param adapter - The host adapter for file conversion, persistence, status, and watching.
|
|
75
|
+
* @param dependencies - Settings, vault, processing, storage-access, and API services used by the facade.
|
|
76
|
+
*/
|
|
77
|
+
constructor(adapter: TAdapter, dependencies: StorageEventManagerBaseDependencies);
|
|
78
|
+
/**
|
|
79
|
+
* Read the setting service's current settings.
|
|
80
|
+
* @returns The current settings value; each access can observe live changes.
|
|
81
|
+
*/
|
|
82
|
+
get settings(): import("../common/types.js").ObsidianLiveSyncSettings;
|
|
83
|
+
/**
|
|
84
|
+
* Resolve whether batching is enabled from the settings active at this access.
|
|
85
|
+
* @returns The live-sync batching value while LiveSync is active, or the general batching value otherwise.
|
|
86
|
+
* @remarks Protected so a host subclass can provide its batching policy.
|
|
87
|
+
*/
|
|
55
88
|
protected get shouldBatchSave(): boolean;
|
|
89
|
+
/**
|
|
90
|
+
* Resolve the minimum batch delay from the current settings.
|
|
91
|
+
* @returns The configured delay value, or the default when the setting is absent.
|
|
92
|
+
*/
|
|
56
93
|
protected get batchSaveMinimumDelay(): number;
|
|
94
|
+
/**
|
|
95
|
+
* Resolve the maximum batch delay from the current settings.
|
|
96
|
+
* @returns The configured delay value, or the default when the setting is absent.
|
|
97
|
+
*/
|
|
57
98
|
protected get batchSaveMaximumDelay(): number;
|
|
58
|
-
|
|
59
|
-
|
|
99
|
+
/**
|
|
100
|
+
* Expose the manager's event-to-operation identity map to its internal effects.
|
|
101
|
+
* @returns The weak map used to find an operation from its event object.
|
|
102
|
+
*/
|
|
103
|
+
private get operations();
|
|
104
|
+
/**
|
|
105
|
+
* Save the supplied queued-event snapshot through the host adapter.
|
|
106
|
+
* @param snapshot - File events and flush sentinels to persist.
|
|
107
|
+
* @returns A promise fulfilled when the adapter saves the snapshot; adapter failures reject it.
|
|
108
|
+
*/
|
|
60
109
|
_saveSnapshot(snapshot: (FileEventItem | FileEventItemSentinel)[]): Promise<void>;
|
|
110
|
+
/**
|
|
111
|
+
* Load the queued-event snapshot through the host adapter.
|
|
112
|
+
* @returns A promise for the saved events, or `null` when no snapshot exists; adapter failures reject it.
|
|
113
|
+
*/
|
|
61
114
|
_loadSnapshot(): Promise<(FileEventItem | FileEventItemSentinel)[] | null>;
|
|
115
|
+
/**
|
|
116
|
+
* Ask the host adapter to classify a supplied file or folder value.
|
|
117
|
+
* @param file - A host value or one of the shared file and folder representations.
|
|
118
|
+
* @returns Whether the adapter recognises the value as a folder.
|
|
119
|
+
*/
|
|
62
120
|
isFolder(file: UXFileInfoStub | UXInternalFileInfoStub | UXFolderInfo | ExtractFolder<TAdapter> | ExtractFile<TAdapter>): boolean;
|
|
121
|
+
/**
|
|
122
|
+
* Ask the host adapter to classify a supplied file or folder value.
|
|
123
|
+
* @param file - A host value or one of the shared file and folder representations.
|
|
124
|
+
* @returns Whether the adapter recognises the value as a file.
|
|
125
|
+
*/
|
|
63
126
|
isFile(file: UXFileInfoStub | UXInternalFileInfoStub | UXFolderInfo | ExtractFolder<TAdapter> | ExtractFile<TAdapter>): boolean;
|
|
64
|
-
protected updateStatus(): void;
|
|
65
127
|
/**
|
|
66
|
-
*
|
|
67
|
-
*
|
|
128
|
+
* Publish the current batch, processing, and unfinished-operation counts through the adapter.
|
|
129
|
+
* @returns Nothing; the adapter's status surface is updated synchronously.
|
|
68
130
|
*/
|
|
131
|
+
protected updateStatus(): void;
|
|
132
|
+
/** Completes restored operations before the host starts watching. */
|
|
69
133
|
snapShotRestored: Promise<void> | null;
|
|
70
134
|
/**
|
|
71
|
-
*
|
|
135
|
+
* Start snapshot restoration and retain the promise used by watcher startup.
|
|
136
|
+
* @returns A promise fulfilled after restoration and replay attempts settle; snapshot or dispatch errors reject it, while failed operation results are reported and retained.
|
|
72
137
|
*/
|
|
73
138
|
restoreState(): Promise<void>;
|
|
74
|
-
|
|
75
|
-
|
|
139
|
+
/**
|
|
140
|
+
* Filter and admit host watcher events into the operation queue.
|
|
141
|
+
* @param params - The watcher events to select and enqueue.
|
|
142
|
+
* @param ctx - Optional host context forwarded with each admitted event.
|
|
143
|
+
* @returns A promise for filtering and queue admission, not for file-handler completion; admission failures are reported and reject it.
|
|
144
|
+
* @remarks The promise may resolve while admitted handlers are still pending. Use `waitForIdle` for the captured processing boundary.
|
|
145
|
+
*/
|
|
76
146
|
appendQueue(params: FileEvent[], ctx?: unknown): Promise<void>;
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
147
|
+
/**
|
|
148
|
+
* Add an already selected event to the buffer and start background snapshotting and dispatch.
|
|
149
|
+
* @param event - The event which has already passed host admission checks.
|
|
150
|
+
* @returns Nothing; processing and persistence failures are reported through manager effects.
|
|
151
|
+
*/
|
|
152
|
+
enqueue(event: FileEventItem): void;
|
|
153
|
+
/**
|
|
154
|
+
* Flush the admissions and operations captured when this call begins.
|
|
155
|
+
* @returns A promise fulfilled when those attempts settle; it rejects with an admission or operation failure.
|
|
156
|
+
* @remarks Later admissions are outside this flush boundary. Batch gates in the captured work are released before waiting.
|
|
157
|
+
*/
|
|
158
|
+
waitForIdle(): Promise<void>;
|
|
159
|
+
/**
|
|
160
|
+
* Stop accepting events, flush current work, and persist the remaining snapshot.
|
|
161
|
+
* @returns A promise fulfilled after the final snapshot write; a flush failure is logged, while a final snapshot failure rejects it.
|
|
162
|
+
*/
|
|
163
|
+
stopWatching(): Promise<void>;
|
|
164
|
+
/**
|
|
165
|
+
* Check whether an unfinished event refers to this path or one of its ancestors.
|
|
166
|
+
* @param filename - The vault-relative path to check.
|
|
167
|
+
* @returns Whether a pending event names the path, an ancestor, or either side of a rename.
|
|
168
|
+
*/
|
|
169
|
+
hasPendingFileEvent(filename: FilePath): boolean;
|
|
170
|
+
/**
|
|
171
|
+
* Check whether the path currently owns an unresolved batching gate.
|
|
172
|
+
* @param filename - The vault-relative path to check.
|
|
173
|
+
* @returns Whether a batch gate is present; this does not indicate whether a handler is still running.
|
|
174
|
+
*/
|
|
175
|
+
isWaiting(filename: FilePath): boolean;
|
|
176
|
+
/**
|
|
177
|
+
* Reuse or create the snapshot entry for a queued event.
|
|
178
|
+
* @param event - A file event or flush sentinel to retain.
|
|
179
|
+
* @param register - Whether to register path-ordering relationships for a file event; defaults to `true`.
|
|
180
|
+
* @returns The retained snapshot entry for the event.
|
|
181
|
+
*/
|
|
85
182
|
private retainEvent;
|
|
183
|
+
/**
|
|
184
|
+
* Log an operation failure which remains pending for retry or recovery.
|
|
185
|
+
* @param error - The failure reported by admission, processing, or persistence.
|
|
186
|
+
* @returns Nothing; the error is logged at notice and verbose levels.
|
|
187
|
+
*/
|
|
86
188
|
private reportOperationFailure;
|
|
189
|
+
/**
|
|
190
|
+
* Record an unsettled attempt as failed and refresh the manager status.
|
|
191
|
+
* @param operation - The pending operation associated with the attempt.
|
|
192
|
+
* @param error - The failure to retain and report.
|
|
193
|
+
* @param attempt - The attempt to fail; defaults to the operation's current attempt.
|
|
194
|
+
* @returns Nothing; an already settled attempt is left unchanged.
|
|
195
|
+
*/
|
|
87
196
|
private failOperation;
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
197
|
+
/**
|
|
198
|
+
* Capture attempts for a finite set of operations and start eligible retries.
|
|
199
|
+
* @param operations - The operations whose current attempts form the capture boundary.
|
|
200
|
+
* @param retryBefore - The latest failure sequence eligible for retry; defaults to no prior failure.
|
|
201
|
+
* @returns The operation-to-attempt map for this boundary.
|
|
202
|
+
*/
|
|
203
|
+
private captureAttempts;
|
|
204
|
+
/**
|
|
205
|
+
* Mark the supplied operations for flushing and release their current batch gates.
|
|
206
|
+
* @param operations - The operations to release.
|
|
207
|
+
* @returns Nothing; no handler completion is awaited here.
|
|
208
|
+
*/
|
|
94
209
|
private releaseOperations;
|
|
95
|
-
private waitForOperations;
|
|
96
210
|
/**
|
|
97
|
-
*
|
|
98
|
-
*
|
|
211
|
+
* Release and await the attempts in the supplied capture.
|
|
212
|
+
* @param attempts - The operation-to-attempt capture to settle.
|
|
213
|
+
* @returns A promise for one success or failure result per captured attempt.
|
|
99
214
|
*/
|
|
100
|
-
|
|
101
|
-
/** Stop watcher admission before draining or preserving accepted work. */
|
|
102
|
-
stopWatching(): Promise<void>;
|
|
215
|
+
private waitForAttempts;
|
|
103
216
|
/**
|
|
104
|
-
*
|
|
217
|
+
* Resolve the current gate for a path as eligible to proceed.
|
|
218
|
+
* @param path - The event path whose gate should proceed.
|
|
219
|
+
* @returns Nothing; the gate is resolved and a snapshot is requested.
|
|
105
220
|
*/
|
|
106
221
|
private _proceedWaiting;
|
|
107
222
|
/**
|
|
108
|
-
*
|
|
223
|
+
* Resolve the current gate for a path as cancelled.
|
|
224
|
+
* @param path - The event path whose gate should be cancelled.
|
|
225
|
+
* @returns Nothing; a coalesced successor may take over the cancelled attempt.
|
|
109
226
|
*/
|
|
110
227
|
private _cancelWaiting;
|
|
111
228
|
/**
|
|
112
|
-
*
|
|
113
|
-
* @param key
|
|
114
|
-
* @param event
|
|
115
|
-
* @param
|
|
229
|
+
* Create a timed batch gate for an event, optionally inheriting a predecessor's wait start.
|
|
230
|
+
* @param path - The path used as the gate key.
|
|
231
|
+
* @param event - The event which owns the gate.
|
|
232
|
+
* @param since - Optional inherited time from which the maximum delay is measured.
|
|
233
|
+
* @returns The gate, including its deadline and proceed promise.
|
|
234
|
+
* @throws An error if another gate already exists for the path.
|
|
116
235
|
*/
|
|
117
236
|
private _addWaiting;
|
|
118
237
|
/**
|
|
119
|
-
*
|
|
238
|
+
* Initialise predecessor ordering and obtain this operation's batch-gate result.
|
|
239
|
+
* @param operation - The operation whose predecessors and gate are being prepared.
|
|
240
|
+
* @returns A promise resolving to the gate's proceed or cancel result, not handler completion.
|
|
241
|
+
*/
|
|
242
|
+
private initialiseOperation;
|
|
243
|
+
/**
|
|
244
|
+
* Run one attempt through gate preparation, ordering, handler dispatch, and snapshot completion.
|
|
245
|
+
* @param operation - The pending event operation to process.
|
|
246
|
+
* @param attempt - The captured attempt whose completion is being driven.
|
|
247
|
+
* @returns A promise fulfilled on successful completion; attempt failures are recorded and rethrown.
|
|
248
|
+
*/
|
|
249
|
+
private processOperation;
|
|
250
|
+
/**
|
|
251
|
+
* Retain an event and await its current processing attempt.
|
|
252
|
+
* @param event - The already selected event to process.
|
|
253
|
+
* @returns A promise fulfilled when the attempt completes; a failed attempt rejects it.
|
|
254
|
+
*/
|
|
255
|
+
processFileEvent(event: FileEventItem): Promise<void>;
|
|
256
|
+
/**
|
|
257
|
+
* Persist the manager snapshot and optionally acknowledge one attempt in that snapshot.
|
|
258
|
+
* @param completion - Optional entry and attempt whose completion should be committed.
|
|
259
|
+
* @returns A promise for the serialised save; snapshot I/O failures reject it.
|
|
260
|
+
*/
|
|
261
|
+
private persistSnapshot;
|
|
262
|
+
/**
|
|
263
|
+
* Wait for the next serialised snapshot write.
|
|
264
|
+
* @returns A promise fulfilled after persistence; save failures reject it.
|
|
120
265
|
*/
|
|
121
|
-
processFileEvent(fei: FileEventItem): Promise<void>;
|
|
122
266
|
_takeSnapshot(): Promise<void>;
|
|
267
|
+
/**
|
|
268
|
+
* Load persisted events, dispatch them, and wait for their replay attempts.
|
|
269
|
+
* @returns A promise for restoration; storage or dispatch errors reject it, while failed attempt results are reported and retained.
|
|
270
|
+
*/
|
|
123
271
|
_restoreFromSnapshot(): Promise<void>;
|
|
124
272
|
/**
|
|
125
|
-
* Dispatch
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
* Snapshot restoration requests completion so its caller can use the replay as
|
|
129
|
-
* a lifecycle boundary. In that mode, a sentinel also waits for every operation
|
|
130
|
-
* dispatched before it, preserving the ordering represented by the snapshot.
|
|
131
|
-
* An individual restored operation failure is logged but does not prevent the
|
|
132
|
-
* following Offline Scanner from reconciling the resulting current state.
|
|
273
|
+
* Dispatch events in the buffer and optionally wait for captured processing attempts.
|
|
274
|
+
* @param options - Queue-run options, including whether to wait for processing.
|
|
275
|
+
* @returns A promise for dispatch; with `waitForProcessing`, failed attempt results are reported rather than thrown as operation errors.
|
|
133
276
|
*/
|
|
134
277
|
protected runQueuedEvents(options?: RunQueuedEventsOptions): Promise<void>;
|
|
135
|
-
protected processingCount: number;
|
|
136
|
-
protected requestProcessQueue(fei: FileEventItem): Promise<void>;
|
|
137
|
-
hasPendingFileEvent(filename: FilePath): boolean;
|
|
138
|
-
isWaiting(filename: FilePath): boolean;
|
|
139
|
-
protected handleFileEvent(queue: FileEventItem): Promise<void>;
|
|
140
|
-
protected cancelRelativeEvent(item: FileEventItem): void;
|
|
141
278
|
/**
|
|
142
|
-
*
|
|
279
|
+
* Start a background snapshot write and report any persistence failure.
|
|
280
|
+
* @returns Nothing; the write is deliberately not awaited by the caller.
|
|
281
|
+
*/
|
|
282
|
+
private _triggerTakeSnapshot;
|
|
283
|
+
/**
|
|
284
|
+
* Throttled callback for requesting a background snapshot write.
|
|
285
|
+
* @returns The callback bound to `_triggerTakeSnapshot` with a 100 ms throttle interval.
|
|
286
|
+
*/
|
|
287
|
+
triggerTakeSnapshot: import("octagonal-wheels/function").ThrottledFunction<() => void>;
|
|
288
|
+
/**
|
|
289
|
+
* Track a handler dispatch in status and restore the processing count in a `finally` block.
|
|
290
|
+
* @param event - The event passed to the host processing hook.
|
|
291
|
+
* @returns A promise fulfilled after handling; handler or status-update failures reject it.
|
|
292
|
+
*/
|
|
293
|
+
protected requestProcessQueue(event: FileEventItem): Promise<void>;
|
|
294
|
+
/**
|
|
295
|
+
* Delegate one event to the shared file-processing handler.
|
|
296
|
+
* @param event - The event to process.
|
|
297
|
+
* @returns A promise fulfilled after handling; processing failures propagate to the attempt.
|
|
298
|
+
* @remarks Protected so hosts can override event handling while retaining the queue lifecycle.
|
|
299
|
+
*/
|
|
300
|
+
protected handleFileEvent(event: FileEventItem): Promise<void>;
|
|
301
|
+
/**
|
|
302
|
+
* Cancel the batch gate associated with a relative event's path.
|
|
303
|
+
* @param event - The event whose path identifies the gate.
|
|
304
|
+
* @returns Nothing; cancelling the gate does not itself complete the operation.
|
|
305
|
+
*/
|
|
306
|
+
protected cancelRelativeEvent(event: FileEventItem): void;
|
|
307
|
+
/**
|
|
308
|
+
* Wait for stored restoration to finish, then register the host watcher callbacks.
|
|
309
|
+
* @returns A promise fulfilled when watcher registration finishes; a restoration failure prevents registration and rejects it.
|
|
143
310
|
*/
|
|
144
311
|
beginWatch(): Promise<void>;
|
|
145
312
|
/**
|
|
146
|
-
*
|
|
313
|
+
* Admit an editor change for a selected file with an active batch gate.
|
|
314
|
+
* @typeParam TEditor - The platform editor type carried by the watcher callback.
|
|
315
|
+
* @typeParam TInfo - The platform editor-change payload type.
|
|
316
|
+
* @param editor - The editor callback value, retained for the host watcher signature.
|
|
317
|
+
* @param info - The editor-change envelope used to resolve file, path, and cached text.
|
|
318
|
+
* @returns Nothing; invalid payloads, disabled batching, active processing, and absent gates are skipped, and admission is not awaited.
|
|
319
|
+
* @remarks Protected so host subclasses can customise editor watcher handling.
|
|
147
320
|
*/
|
|
148
321
|
protected watchEditorChange<TEditor = unknown, TInfo = unknown>(editor: TEditor, info: TInfo): void;
|
|
322
|
+
/**
|
|
323
|
+
* Forward a host create notification to facade admission.
|
|
324
|
+
* @typeParam TFile - The host file payload type.
|
|
325
|
+
* @typeParam TCtx - The host watcher context type.
|
|
326
|
+
* @param file - The untrusted host notification payload.
|
|
327
|
+
* @param ctx - Optional host context forwarded to admission.
|
|
328
|
+
* @returns Nothing; unrecognised payloads and paths reported as already processing are skipped, and admission is not awaited.
|
|
329
|
+
* @remarks This remains a protected override point; the base implementation shares validation and conversion through `forwardVaultEvent`.
|
|
330
|
+
*/
|
|
149
331
|
protected watchVaultCreate<TFile = unknown, TCtx = unknown>(file: TFile, ctx?: TCtx): void;
|
|
332
|
+
/**
|
|
333
|
+
* Forward a host change notification to facade admission.
|
|
334
|
+
* @typeParam TFile - The host file payload type.
|
|
335
|
+
* @typeParam TCtx - The host watcher context type.
|
|
336
|
+
* @param file - The untrusted host notification payload.
|
|
337
|
+
* @param ctx - Optional host context forwarded to admission.
|
|
338
|
+
* @returns Nothing; unrecognised payloads and paths reported as already processing are skipped, and admission is not awaited.
|
|
339
|
+
* @remarks This remains a protected override point; the base implementation shares validation and conversion through `forwardVaultEvent`.
|
|
340
|
+
*/
|
|
150
341
|
protected watchVaultChange<TFile = unknown, TCtx = unknown>(file: TFile, ctx?: TCtx): void;
|
|
342
|
+
/**
|
|
343
|
+
* Forward a host delete notification to facade admission.
|
|
344
|
+
* @typeParam TFile - The host file payload type.
|
|
345
|
+
* @typeParam TCtx - The host watcher context type.
|
|
346
|
+
* @param file - The untrusted host notification payload.
|
|
347
|
+
* @param ctx - Optional host context forwarded to admission.
|
|
348
|
+
* @returns Nothing; unrecognised payloads and paths reported as already processing are skipped, and admission is not awaited.
|
|
349
|
+
* @remarks This remains a protected override point; the base implementation shares validation and conversion through `forwardVaultEvent`.
|
|
350
|
+
*/
|
|
151
351
|
protected watchVaultDelete<TFile = unknown, TCtx = unknown>(file: TFile, ctx?: TCtx): void;
|
|
352
|
+
/**
|
|
353
|
+
* Forward a host rename as one operation with its source path.
|
|
354
|
+
* @typeParam TFile - The host file payload type.
|
|
355
|
+
* @typeParam TCtx - The host watcher context type.
|
|
356
|
+
* @param file - The untrusted host notification payload.
|
|
357
|
+
* @param oldPath - The path the file was renamed from.
|
|
358
|
+
* @param ctx - Optional host context forwarded to admission.
|
|
359
|
+
* @returns Nothing; unrecognised payloads are skipped, and admission is not awaited.
|
|
360
|
+
* @remarks Rename bypasses processing-path suppression and batching. This protected hook remains overridable by host subclasses.
|
|
361
|
+
*/
|
|
152
362
|
protected watchVaultRename<TFile = unknown, TCtx = unknown>(file: TFile, oldPath: string, ctx?: TCtx): void;
|
|
363
|
+
/**
|
|
364
|
+
* Route a raw internal-file callback to the host-specific raw-event hook.
|
|
365
|
+
* @param path - The vault-relative path reported by the host watcher.
|
|
366
|
+
* @returns Nothing; while ignore-file handling is enabled, the target check is started before the hook.
|
|
367
|
+
* @remarks Protected so platform subclasses can provide their raw-event policy.
|
|
368
|
+
*/
|
|
153
369
|
protected watchVaultRawEvents(path: FilePath): void;
|
|
370
|
+
/**
|
|
371
|
+
* Host extension point for platform-specific raw internal-file handling.
|
|
372
|
+
* @param path - The vault-relative internal-file path to inspect.
|
|
373
|
+
* @returns A resolved promise in the base implementation; subclasses may perform asynchronous handling.
|
|
374
|
+
*/
|
|
154
375
|
protected _watchVaultRawEvents(path: FilePath): Promise<void>;
|
|
155
376
|
}
|
|
156
|
-
export {};
|