@vrtmrz/livesync-commonlib 0.3.2 → 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.
Files changed (87) hide show
  1. package/README.md +17 -0
  2. package/dist/common/models/fileaccess.definition.d.ts +35 -0
  3. package/dist/common/models/fileaccess.definition.js +11 -0
  4. package/dist/common/typeUtils.d.ts +27 -4
  5. package/dist/interfaces/FileHandler.d.ts +1 -1
  6. package/dist/managers/EntryManager/EntryManagerImpls.js +1 -1
  7. package/dist/managers/StorageEventManager/admission.d.ts +50 -0
  8. package/dist/managers/StorageEventManager/admission.js +129 -0
  9. package/dist/managers/StorageEventManager/batching.d.ts +93 -0
  10. package/dist/managers/StorageEventManager/batching.js +97 -0
  11. package/dist/managers/StorageEventManager/operations.d.ts +142 -0
  12. package/dist/managers/StorageEventManager/operations.js +69 -0
  13. package/dist/managers/StorageEventManager/processing.d.ts +63 -0
  14. package/dist/managers/StorageEventManager/processing.js +94 -0
  15. package/dist/managers/StorageEventManager/queue.d.ts +73 -0
  16. package/dist/managers/StorageEventManager/queue.js +113 -0
  17. package/dist/managers/StorageEventManager/retry.d.ts +33 -0
  18. package/dist/managers/StorageEventManager/retry.js +31 -0
  19. package/dist/managers/StorageEventManager/snapshot.d.ts +46 -0
  20. package/dist/managers/StorageEventManager/snapshot.js +53 -0
  21. package/dist/managers/StorageEventManager/state.d.ts +155 -0
  22. package/dist/managers/StorageEventManager/state.js +105 -0
  23. package/dist/managers/StorageEventManager/watching.d.ts +93 -0
  24. package/dist/managers/StorageEventManager/watching.js +36 -0
  25. package/dist/managers/StorageEventManager.d.ts +303 -83
  26. package/dist/managers/StorageEventManager.js +457 -547
  27. package/dist/p2p/P2PService.d.ts +10 -1
  28. package/dist/p2p/P2PService.js +25 -2
  29. package/dist/p2p/index.d.ts +4 -1
  30. package/dist/p2p/index.js +2 -0
  31. package/dist/p2p/p2pDiagnostics.d.ts +35 -0
  32. package/dist/p2p/p2pDiagnostics.js +76 -0
  33. package/dist/pouchdb/ReplicatorShim.batch.d.ts +30 -0
  34. package/dist/pouchdb/ReplicatorShim.batch.js +62 -0
  35. package/dist/pouchdb/ReplicatorShim.d.ts +14 -1
  36. package/dist/pouchdb/ReplicatorShim.js +64 -80
  37. package/dist/replication/trystero/P2PLogCollector.d.ts +12 -0
  38. package/dist/replication/trystero/P2PLogCollector.js +107 -72
  39. package/dist/replication/trystero/P2PRoomSessionOwner.d.ts +4 -0
  40. package/dist/replication/trystero/P2PRoomSessionOwner.js +39 -2
  41. package/dist/replication/trystero/TrysteroReplicator.d.ts +21 -24
  42. package/dist/replication/trystero/TrysteroReplicator.js +191 -69
  43. package/dist/replication/trystero/TrysteroReplicatorP2PServer.js +11 -0
  44. package/dist/replication/trystero/p2pReplicationDiagnostics.d.ts +9 -0
  45. package/dist/replication/trystero/p2pReplicationDiagnostics.js +51 -0
  46. package/dist/replication/trystero/p2pReplicationProgress.d.ts +15 -0
  47. package/dist/replication/trystero/p2pReplicationProgress.js +37 -0
  48. package/dist/replication/trystero/types.d.ts +3 -0
  49. package/dist/serviceModules/ServiceFileHandlerBase/chunks.d.ts +10 -0
  50. package/dist/serviceModules/ServiceFileHandlerBase/chunks.js +51 -0
  51. package/dist/serviceModules/ServiceFileHandlerBase/context.d.ts +168 -0
  52. package/dist/serviceModules/ServiceFileHandlerBase/context.js +15 -0
  53. package/dist/serviceModules/ServiceFileHandlerBase/deletion.d.ts +40 -0
  54. package/dist/serviceModules/ServiceFileHandlerBase/deletion.js +142 -0
  55. package/dist/serviceModules/ServiceFileHandlerBase/events.d.ts +20 -0
  56. package/dist/serviceModules/ServiceFileHandlerBase/events.js +205 -0
  57. package/dist/serviceModules/ServiceFileHandlerBase/locking.d.ts +23 -0
  58. package/dist/serviceModules/ServiceFileHandlerBase/locking.js +51 -0
  59. package/dist/serviceModules/ServiceFileHandlerBase/protection.d.ts +26 -0
  60. package/dist/serviceModules/ServiceFileHandlerBase/protection.js +67 -0
  61. package/dist/serviceModules/ServiceFileHandlerBase/provenance.d.ts +174 -0
  62. package/dist/serviceModules/ServiceFileHandlerBase/provenance.js +182 -0
  63. package/dist/serviceModules/ServiceFileHandlerBase/reflection.d.ts +48 -0
  64. package/dist/serviceModules/ServiceFileHandlerBase/reflection.js +344 -0
  65. package/dist/serviceModules/ServiceFileHandlerBase/renaming.d.ts +23 -0
  66. package/dist/serviceModules/ServiceFileHandlerBase/renaming.js +77 -0
  67. package/dist/serviceModules/ServiceFileHandlerBase/saving.d.ts +40 -0
  68. package/dist/serviceModules/ServiceFileHandlerBase/saving.js +306 -0
  69. package/dist/serviceModules/ServiceFileHandlerBase/scanning.d.ts +22 -0
  70. package/dist/serviceModules/ServiceFileHandlerBase/scanning.js +93 -0
  71. package/dist/serviceModules/ServiceFileHandlerBase/selection.d.ts +58 -0
  72. package/dist/serviceModules/ServiceFileHandlerBase/selection.js +94 -0
  73. package/dist/serviceModules/ServiceFileHandlerBase/storage.d.ts +55 -0
  74. package/dist/serviceModules/ServiceFileHandlerBase/storage.js +37 -0
  75. package/dist/serviceModules/ServiceFileHandlerBase.d.ts +119 -182
  76. package/dist/serviceModules/ServiceFileHandlerBase.js +182 -1402
  77. package/dist/services/base/APIService.d.ts +10 -0
  78. package/dist/services/base/APIService.js +13 -0
  79. package/dist/services/base/IService.d.ts +2 -0
  80. package/docs/conflict-resolution.md +3 -1
  81. package/docs/development.md +36 -0
  82. package/docs/journal-receive-recovery.md +7 -4
  83. package/docs/offline-scanner.md +5 -1
  84. package/docs/p2p-transport-lifecycle.md +125 -11
  85. package/docs/releasing.md +6 -0
  86. package/docs/storage-events-and-reflection.md +203 -19
  87. package/package.json +2 -2
@@ -0,0 +1,155 @@
1
+ /**
2
+ * Per-manager in-memory ownership, admission, and ordering for retained file-event intent.
3
+ * Snapshot writes are delegated to the snapshot module; these state transitions do not commit them.
4
+ */
5
+ import type { FileEventItem, FilePath } from "../../common/types.js";
6
+ import { type FileEventAttempt, type PendingFileEvent } from "./operations.js";
7
+ /** Queue marker which closes the ordered boundary before a delete or rename. */
8
+ export declare const TYPE_SENTINEL_FLUSH = "SENTINEL_FLUSH";
9
+ /** Queue shape for an ordering marker; it does not own a file operation. */
10
+ export type FileEventItemSentinel = {
11
+ type: typeof TYPE_SENTINEL_FLUSH;
12
+ };
13
+ /** Items which can appear in the host buffer and durable event snapshot. */
14
+ export type QueuedFileEvent = FileEventItem | FileEventItemSentinel;
15
+ /** One in-flight admission and the operation attempts included in its completion boundary. */
16
+ export type EventAdmission = {
17
+ /** Time captured when this admission began. */
18
+ acceptedAt: number;
19
+ /** Settles when the admission has finished registering or rejecting its events. */
20
+ completion: Promise<void>;
21
+ /** Attempts accepted by this admission, retained for a concurrent finite flush. */
22
+ operations: Map<PendingFileEvent, FileEventAttempt>;
23
+ /** Failure-sequence cutoff captured when the admission began. */
24
+ failureBoundary: number;
25
+ /** Whether a flush has captured this admission, including operations it registers later. */
26
+ flushRequested: boolean;
27
+ };
28
+ /** Queue and persistence view of one event, optionally linked to its durable operation. */
29
+ export type PendingSnapshotEntry = {
30
+ /** Event intent written to or restored from the existing snapshot format. */
31
+ event: QueuedFileEvent;
32
+ /** Stable insertion order within this manager's pending snapshot. */
33
+ sequence: number;
34
+ /** Provisional completion within a serial snapshot step; a failed save rolls it back. */
35
+ completed: boolean;
36
+ /** Durable operation for file events; sentinels have no operation. */
37
+ operation?: PendingFileEvent;
38
+ /** Whether a sentinel has passed through dispatch and may be acknowledged after its predecessors. */
39
+ dispatched?: boolean;
40
+ };
41
+ /** Completion acknowledgement tied to both the retained entry and its exact attempt. */
42
+ export type SnapshotCompletion = {
43
+ entry: PendingSnapshotEntry;
44
+ attempt: FileEventAttempt;
45
+ };
46
+ /** Optional wait policy for a queue dispatch request. */
47
+ export type RunQueuedEventsOptions = {
48
+ waitForProcessing?: boolean;
49
+ };
50
+ /** Mutable ownership, admission, and persistence state for one manager. */
51
+ export interface StorageEventState {
52
+ /** Ordered intents still requiring durable acknowledgement. */
53
+ pendingSnapshot: Map<QueuedFileEvent, PendingSnapshotEntry>;
54
+ /** Event-object lookup used to preserve operation identity across repeated retention. */
55
+ operations: WeakMap<FileEventItem, PendingFileEvent>;
56
+ /** Latest unresolved operation touching each path. */
57
+ latestByPath: Map<string, PendingFileEvent>;
58
+ /** Monotonic counter incremented when a new event is retained. */
59
+ nextSequence: number;
60
+ /** Monotonic failure counter; its current value bounds a new retry request. */
61
+ nextFailureSequence: number;
62
+ /** Admission switch controlled by the owning manager's lifecycle. */
63
+ acceptingEvents: boolean;
64
+ /** Admissions in progress which a finite flush must account for. */
65
+ admissions: Set<EventAdmission>;
66
+ /** Serial tail for completion marking, snapshot saving, and rollback. */
67
+ snapshotTail: Promise<void>;
68
+ /** Stable key so concurrent dispatch calls for this manager share one run. */
69
+ readonly dispatchKey: symbol;
70
+ }
71
+ /** Preserve the host's protected buffer, including replacement during restoration. */
72
+ export interface StorageEventBuffer {
73
+ /** Read the current ordered buffer without taking ownership of its array. */
74
+ read(): readonly QueuedFileEvent[];
75
+ /** Replace the host buffer, including when restoration requires replacing its array. */
76
+ replace(events: QueuedFileEvent[]): void;
77
+ /** Append one event or sentinel at the current tail. */
78
+ append(event: QueuedFileEvent): void;
79
+ /** Remove and return the next queued item. */
80
+ shift(): QueuedFileEvent | undefined;
81
+ }
82
+ /** Host notifications kept outside the state owner. */
83
+ export interface StorageEventNotifications {
84
+ /** Refresh the host's view of pending local work. */
85
+ updateStatus(): void;
86
+ /** Report retained work without changing the result observed by its callers. */
87
+ reportFailure(error: unknown): void;
88
+ }
89
+ /**
90
+ * Create empty ownership state for one manager instance.
91
+ * @returns Fresh maps, counters, admission tracking, and a resolved initial snapshot tail.
92
+ * @remarks The state is isolated to one manager; no host callbacks or persistence are invoked here.
93
+ */
94
+ export declare function createStorageEventState(): StorageEventState;
95
+ /**
96
+ * Retain an event once and reuse its durable operation when the same event is encountered again.
97
+ * @param state - The manager state which owns the snapshot entry and event-to-operation identity map.
98
+ * @param event - A file event or ordering sentinel to retain.
99
+ * @param register - Whether a file operation should also enter the per-path ordering index.
100
+ * @returns The existing entry for this event object, or the newly created entry.
101
+ * @remarks Snapshot collection passes register as false for events surfaced by batch gates, so persistence
102
+ * discovery cannot become their first path-indexing moment and change path ownership or ordering. The registered
103
+ * flag independently prevents later duplicate indexing. Retention does not write a snapshot or start a handler;
104
+ * a new operation captures the current failure sequence as its boundary.
105
+ */
106
+ export declare function retainFileEvent(state: StorageEventState, event: QueuedFileEvent, register?: boolean): PendingSnapshotEntry;
107
+ /**
108
+ * Retain buffered events in order and attach an adjacent sentinel to its delete or rename.
109
+ * @param state - The manager state receiving entries and ordering barriers.
110
+ * @param events - The current ordered host buffer; it is read-only and is not replaced here.
111
+ * @returns Nothing; retained entries and any delete/rename barrier are updated in memory.
112
+ * @remarks A sentinel applies to the next buffered file event only when that event is DELETE or RENAME.
113
+ * This records the boundary for later dispatch; it does not persist the snapshot.
114
+ */
115
+ export declare function retainBufferedFileEvents(state: StorageEventState, events: readonly QueuedFileEvent[]): void;
116
+ /**
117
+ * Select retained file operations before an exclusive sequence boundary.
118
+ * @param state - The manager state whose retained entries are inspected.
119
+ * @param before - The first excluded sequence; the default includes all retained operations.
120
+ * @returns Operations whose entry sequence is strictly less than before, in snapshot insertion order.
121
+ * @remarks Sentinels are excluded. The strict comparison lets a sentinel wait for predecessors without capturing
122
+ * itself or later operations. This is a read-only selection and does not capture attempts or retry failures.
123
+ */
124
+ export declare function pendingFileOperations(state: StorageEventState, before?: number): PendingFileEvent[];
125
+ /**
126
+ * Settle an attempt as failed once and assign its position in the manager's failure sequence.
127
+ * @param state - The manager state which owns the monotonically increasing failure sequence.
128
+ * @param attempt - The attempt whose completion promise may still be unsettled.
129
+ * @param error - The failure observed by this attempt.
130
+ * @returns True when this call records and resolves the failure; false when the attempt was already settled.
131
+ * @remarks Only in-memory attempt state changes here. The durable operation remains retained, and no snapshot
132
+ * write is performed.
133
+ */
134
+ export declare function failFileEventAttempt(state: StorageEventState, attempt: FileEventAttempt, error: unknown): boolean;
135
+ /**
136
+ * Settle a successful attempt and remove only path-index entries which it still owns.
137
+ * @param state - The manager state whose latest-operation index may be cleared.
138
+ * @param operation - The durable operation completed by this attempt.
139
+ * @param attempt - The attempt whose handler completed and whose completion-snapshot step has settled.
140
+ * @returns Nothing; records success and conditionally clears the operation's current path entries.
141
+ * @remarks The caller must await the completion-snapshot step before calling this function; that step may be a
142
+ * no-op if the entry or attempt has already been replaced. A newer operation or replacement attempt keeps its
143
+ * index entries because both operation identity and current-attempt identity are checked. This function records
144
+ * the in-memory result; it does not write or commit a snapshot.
145
+ */
146
+ export declare function completeFileEventAttempt(state: StorageEventState, operation: PendingFileEvent, attempt: FileEventAttempt): void;
147
+ /**
148
+ * Check whether unfinished retained intent covers a queried path.
149
+ * @param state - The manager state containing retained snapshot entries.
150
+ * @param filename - The queried path.
151
+ * @returns True when an event path is the queried path or one of its ancestors; rename source and related paths
152
+ * are both considered. False for completed entries, sentinels, or unrelated paths.
153
+ * @remarks This is a read-only prefix check. It does not test whether the queried path is an ancestor of an event.
154
+ */
155
+ export declare function hasPendingStorageEvent(state: StorageEventState, filename: FilePath): boolean;
@@ -0,0 +1,105 @@
1
+ import {
2
+ createFileEventAttempt,
3
+ getFileEventPaths
4
+ } from "./operations.js";
5
+ const TYPE_SENTINEL_FLUSH = "SENTINEL_FLUSH";
6
+ function createStorageEventState() {
7
+ return {
8
+ pendingSnapshot: /* @__PURE__ */ new Map(),
9
+ operations: /* @__PURE__ */ new WeakMap(),
10
+ latestByPath: /* @__PURE__ */ new Map(),
11
+ nextSequence: 0,
12
+ nextFailureSequence: 0,
13
+ acceptingEvents: true,
14
+ admissions: /* @__PURE__ */ new Set(),
15
+ snapshotTail: Promise.resolve(),
16
+ dispatchKey: /* @__PURE__ */ Symbol("storageEventDispatch")
17
+ };
18
+ }
19
+ function registerOperation(state, operation) {
20
+ if (operation.registered) return;
21
+ operation.registered = true;
22
+ for (const path of getFileEventPaths(operation.event)) {
23
+ const previous = state.latestByPath.get(path);
24
+ if (previous && !previous.attempt.result?.ok) operation.predecessors.set(path, previous);
25
+ state.latestByPath.set(path, operation);
26
+ }
27
+ }
28
+ function retainFileEvent(state, event, register = true) {
29
+ const existing = state.pendingSnapshot.get(event);
30
+ if (existing) {
31
+ if (register && existing.operation) registerOperation(state, existing.operation);
32
+ return existing;
33
+ }
34
+ const entry = { event, sequence: ++state.nextSequence, completed: false };
35
+ if (event.type !== TYPE_SENTINEL_FLUSH) {
36
+ const operation = state.operations.get(event) ?? {
37
+ event,
38
+ sequence: entry.sequence,
39
+ acceptedAt: Date.now(),
40
+ attempt: createFileEventAttempt(),
41
+ failureBoundary: state.nextFailureSequence,
42
+ initialised: false,
43
+ registered: false,
44
+ predecessors: /* @__PURE__ */ new Map(),
45
+ prerequisites: /* @__PURE__ */ new Set(),
46
+ flushRequested: false
47
+ };
48
+ entry.operation = operation;
49
+ if (register) registerOperation(state, operation);
50
+ state.operations.set(event, operation);
51
+ }
52
+ state.pendingSnapshot.set(event, entry);
53
+ return entry;
54
+ }
55
+ function retainBufferedFileEvents(state, events) {
56
+ let barrierBefore;
57
+ for (const event of events) {
58
+ const entry = retainFileEvent(state, event);
59
+ if (event.type === TYPE_SENTINEL_FLUSH) barrierBefore = entry.sequence;
60
+ else {
61
+ if (event.type === "DELETE" || event.type === "RENAME") entry.operation.barrierBefore ??= barrierBefore;
62
+ barrierBefore = void 0;
63
+ }
64
+ }
65
+ }
66
+ function pendingFileOperations(state, before = Number.POSITIVE_INFINITY) {
67
+ return [...state.pendingSnapshot.values()].flatMap(
68
+ (entry) => entry.operation && entry.sequence < before ? [entry.operation] : []
69
+ );
70
+ }
71
+ function failFileEventAttempt(state, attempt, error) {
72
+ if (attempt.result) return false;
73
+ attempt.result = { ok: false, error };
74
+ attempt.failureSequence = ++state.nextFailureSequence;
75
+ attempt.completion.resolve(attempt.result);
76
+ return true;
77
+ }
78
+ function completeFileEventAttempt(state, operation, attempt) {
79
+ attempt.result = { ok: true };
80
+ attempt.completion.resolve(attempt.result);
81
+ for (const path of getFileEventPaths(operation.event)) {
82
+ if (state.latestByPath.get(path) === operation && operation.attempt === attempt)
83
+ state.latestByPath.delete(path);
84
+ }
85
+ }
86
+ function hasPendingStorageEvent(state, filename) {
87
+ for (const entry of state.pendingSnapshot.values()) {
88
+ if (entry.completed || entry.event.type === TYPE_SENTINEL_FLUSH) continue;
89
+ if (getFileEventPaths(entry.event).some(
90
+ (path) => path && (filename === path || filename.startsWith(`${path}/`))
91
+ ))
92
+ return true;
93
+ }
94
+ return false;
95
+ }
96
+ export {
97
+ TYPE_SENTINEL_FLUSH,
98
+ completeFileEventAttempt,
99
+ createStorageEventState,
100
+ failFileEventAttempt,
101
+ hasPendingStorageEvent,
102
+ pendingFileOperations,
103
+ retainBufferedFileEvents,
104
+ retainFileEvent
105
+ };
@@ -0,0 +1,93 @@
1
+ /**
2
+ * Convert host watcher notifications into file-event admissions.
3
+ * Payload checks belong here; durable ownership and handler completion belong
4
+ * to the admission and queue modules after the host facade accepts an event.
5
+ */
6
+ import type { FilePath } from "../../common/types.js";
7
+ import type { FileEvent } from "../../interfaces/StorageEventManager.js";
8
+ import type { IStorageEventManagerAdapter, IStorageEventTypeGuardAdapter } from "../adapters/index.js";
9
+ /** The rename variant requires the source path and remains one operation. */
10
+ export type WatchedVaultEvent = {
11
+ type: "CREATE" | "CHANGED" | "DELETE";
12
+ file: unknown;
13
+ } | {
14
+ type: "RENAME";
15
+ file: unknown;
16
+ oldPath: string;
17
+ };
18
+ /** Resolve the current adapter and virtual admission method when a notification arrives. */
19
+ export interface StorageEventWatchEffects<TFile, TFolder> {
20
+ /** Resolve the current adapter without rebinding its guard or converter methods. */
21
+ adapter(): Pick<IStorageEventManagerAdapter<TFile, TFolder>, "typeGuard" | "converter">;
22
+ /** Report a currently processed path for notification suppression; rename bypasses this check. */
23
+ isProcessing(path: FilePath): boolean;
24
+ /** Complete facade admission without awaiting the admitted file handlers. */
25
+ append(events: FileEvent[], ctx?: unknown): Promise<void>;
26
+ }
27
+ /**
28
+ * Narrow a host-supplied path at the watcher boundary.
29
+ * The host owns its Vault-relative namespace; this checks the payload type and
30
+ * preserves the path verbatim rather than normalising database prefixes.
31
+ *
32
+ * @param value - The path value received from the host.
33
+ * @returns Whether the value can be treated as a host storage path.
34
+ */
35
+ export declare function isStorageEventPath(value: unknown): value is FilePath;
36
+ /**
37
+ * Combine the adapter's platform-specific file guard with the path shape needed
38
+ * by watcher admission. A folder or unrecognised payload never reaches conversion.
39
+ *
40
+ * @typeParam TFile - The file type recognised by the platform adapter.
41
+ * @typeParam TFolder - The folder type recognised by the same adapter.
42
+ * @param file - The notification payload before type narrowing.
43
+ * @param guard - The adapter which owns platform-specific file recognition.
44
+ * @returns Whether both the platform-file and storage-path contracts hold.
45
+ */
46
+ export declare function isWatchedFile<TFile, TFolder>(file: unknown, guard: IStorageEventTypeGuardAdapter<TFile, TFolder>): file is TFile & {
47
+ path: FilePath;
48
+ };
49
+ /**
50
+ * Forward a validated notification through the facade's admission callback.
51
+ * Create, change, and delete suppress notifications while the path is being processed.
52
+ * Rename retains its distinct route: it bypasses that suppression and batching
53
+ * so the queue can preserve the source/destination ordering as one operation.
54
+ * This returns after admission starts; append owns asynchronous failure reporting.
55
+ *
56
+ * @typeParam TFile - The platform file representation accepted by the adapter.
57
+ * @typeParam TFolder - The folder representation used by the same adapter.
58
+ * @param notification - The host event; rename includes the previous path.
59
+ * @param ctx - The host context forwarded unchanged to admission.
60
+ * @param effects - Current adapter access, processing-state checks, and virtual admission.
61
+ * @returns No completion result; accepted notifications start asynchronous admission.
62
+ * @remarks
63
+ * The facade retains its protected watcher methods so host overrides still run.
64
+ * This helper centralises conversion; a host normally extends the adapter or those hooks.
65
+ */
66
+ export declare function forwardVaultEvent<TFile, TFolder>(notification: WatchedVaultEvent, ctx: unknown, effects: StorageEventWatchEffects<TFile, TFolder>): void;
67
+ /**
68
+ * Validate the common editor envelope before the facade reads its live batching setting.
69
+ *
70
+ * @param info - The editor notification supplied by a platform watcher.
71
+ * @returns Whether a path property exists; its value is checked when the change is read.
72
+ */
73
+ export declare function hasEditorChangePath(info: unknown): info is {
74
+ path: unknown;
75
+ };
76
+ /**
77
+ * Extract a usable editor change without admitting it or changing batch gates.
78
+ * Recognised platform files supply their own path; other host editor payloads
79
+ * retain the envelope-path fallback. Optional cached text is accepted only as text.
80
+ *
81
+ * @param info - The editor envelope after its path property has been established.
82
+ * @param isFile - Platform recognition used to choose the authoritative path.
83
+ * @returns The selected file, path, and optional text, or null when the path is unusable.
84
+ */
85
+ export declare function readEditorFileChange(info: {
86
+ path: unknown;
87
+ file?: unknown;
88
+ data?: unknown;
89
+ }, isFile: (file: unknown) => boolean): {
90
+ file: unknown;
91
+ path: FilePath;
92
+ data: string;
93
+ };
@@ -0,0 +1,36 @@
1
+ function isStorageEventPath(value) {
2
+ return typeof value === "string";
3
+ }
4
+ function hasStorageEventPath(value) {
5
+ return typeof value === "object" && value !== null && "path" in value && isStorageEventPath(value.path);
6
+ }
7
+ function isWatchedFile(file, guard) {
8
+ return guard.isFile(file) && hasStorageEventPath(file);
9
+ }
10
+ function forwardVaultEvent(notification, ctx, effects) {
11
+ const adapter = effects.adapter();
12
+ const file = notification.file;
13
+ if (!isWatchedFile(file, adapter.typeGuard)) return;
14
+ if (notification.type !== "RENAME" && effects.isProcessing(file.path)) return;
15
+ const fileInfo = notification.type === "DELETE" ? adapter.converter.toFileInfo(file, true) : adapter.converter.toFileInfo(file);
16
+ const event = notification.type === "RENAME" ? { type: "RENAME", file: fileInfo, oldPath: notification.oldPath, skipBatchWait: true } : { type: notification.type, file: fileInfo };
17
+ void effects.append([event], ctx);
18
+ }
19
+ function hasEditorChangePath(info) {
20
+ return typeof info === "object" && info !== null && "path" in info;
21
+ }
22
+ function readEditorFileChange(info, isFile) {
23
+ if (!("file" in info) || !info.file) return null;
24
+ const file = info.file;
25
+ const path = isFile(file) ? hasStorageEventPath(file) ? file.path : void 0 : info.path;
26
+ if (!isStorageEventPath(path) || !path) return null;
27
+ const data = "data" in info && typeof info.data === "string" ? info.data : void 0;
28
+ return { file, path, data };
29
+ }
30
+ export {
31
+ forwardVaultEvent,
32
+ hasEditorChangePath,
33
+ isStorageEventPath,
34
+ isWatchedFile,
35
+ readEditorFileChange
36
+ };