mirror of
https://github.com/vrtmrz/obsidian-livesync.git
synced 2026-11-14 20:20:12 +00:00
Separate host-independent helpers under common/core and colocate feature support code with its owners. Update imports, tests, and source-layout guidance while preserving runtime behaviour.
25 lines
1.0 KiB
TypeScript
25 lines
1.0 KiB
TypeScript
import { createOwnedResource } from "octagonal-wheels/resource";
|
|
import type { RemoteDBSettings } from "@vrtmrz/livesync-commonlib/compat/common/types";
|
|
|
|
/**
|
|
* Closeable surface of a concrete Replicator owned by one private resource.
|
|
*
|
|
* It deliberately exposes no active-provider controls: the resource may use
|
|
* the helper for one bounded operation, then must dispose it without
|
|
* publishing or replacing the active Replicator.
|
|
*/
|
|
export interface ResourceReplicator {
|
|
closeReplication(): void | Promise<void>;
|
|
}
|
|
|
|
/** Create one idempotent asynchronous disposer for a private Replicator. */
|
|
export function createReplicatorDisposer(replicator: ResourceReplicator): () => Promise<void> {
|
|
const resource = createOwnedResource(replicator, (owned) => Promise.resolve().then(() => owned.closeReplication()));
|
|
return () => Promise.resolve(resource.dispose());
|
|
}
|
|
|
|
/** Fence a finite resource from later edits to its source settings object. */
|
|
export function snapshotRemoteSettings(setting: RemoteDBSettings): RemoteDBSettings {
|
|
return { ...setting };
|
|
}
|