Skip to content

vaultmd / withFileTransform

Function: withFileTransform()

withFileTransform(fullPath, lockKey, relForCommit, transform, opts?): Promise<TransformResult>

Defined in: src/locked-file/transform.ts:26

Apply a transform to a vault file inside the per-file lock, with optimistic-concurrency retry on mtime conflicts. The transform callback receives the current file content (or null if the file is absent) and must return the desired new content, or null to leave the file untouched.

Parameters

fullPath

string

Absolute filesystem path to the target file.

lockKey

string

Canonical/case-folded serialization key — pass VaultIo.toKey(rel).

relForCommit

string

Display path written to CommitEvent.path — pass VaultIo.toVaultRelative(rel).

transform

(current) => string | null

Pure function from current content to desired content, or null for no-op.

opts?

TransformOpts = {}

Optional behaviour overrides — see TransformOpts.

Returns

Promise<TransformResult>

A TransformResult describing the outcome and final content.