CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-mem-fs-editor

File edition helpers working on top of mem-fs

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

state-management.mddocs/

State Management

File state management system for tracking file lifecycle states, commit status, and managing pending changes in the mem-fs-editor store.

Capabilities

File State Management

Set, check, and manage file states for tracking modifications and deletions.

/**
 * Set the state of a file
 * @param file - The file object to modify
 * @param state - The state value to set ('modified' | 'deleted')
 */
function setFileState(file: MemFsEditorFile, state: 'modified' | 'deleted'): void;

/**
 * Check if a file is new (doesn't exist on disk)
 * @param file - The file object to check
 * @returns True if file is new, false if it exists on disk
 */
function isFileNew(file: MemFsEditorFile): boolean;

/**
 * Check if a file's state is marked as modified
 * @param file - The file object to check
 * @returns True if file state is 'modified'
 */
function isFileStateModified(file: MemFsEditorFile): boolean;

/**
 * Set a file's state to modified
 * @param file - The file object to modify
 */
function setModifiedFileState(file: MemFsEditorFile): void;

/**
 * Check if a file's state is marked as deleted
 * @param file - The file object to check
 * @returns True if file state is 'deleted'
 */
function isFileStateDeleted(file: MemFsEditorFile): boolean;

/**
 * Set a file's state to deleted
 * @param file - The file object to modify
 */
function setDeletedFileState(file: MemFsEditorFile): void;

/**
 * Check if a file has pending changes (modified or deleted but not new)
 * @param file - The file object to check
 * @returns True if file has pending changes
 */
function isFilePending(file: MemFsEditorFile): boolean;

Commit State Management

Manage file commit status and track which files have been committed to disk.

/**
 * Mark a file as committed to disk
 * @param file - The file object to mark as committed
 */
function setCommittedFile(file: MemFsEditorFile): void;

/**
 * Check if a file has been committed to disk
 * @param file - The file object to check
 * @returns True if file is committed
 */
function isFileCommitted(file: MemFsEditorFile): boolean;

State Reset and Cleanup

Reset file states and clean up internal state tracking properties.

/**
 * Reset the file state (remove state property)
 * @param file - The file object to reset
 */
function resetFileState(file: MemFsEditorFile): void;

/**
 * Delete commit-related states (stateCleared and committed properties)
 * @param file - The file object to clean up
 */
function resetFileCommitStates(file: MemFsEditorFile): void;

/**
 * Delete all mem-fs-editor related states (complete cleanup)
 * @param file - The file object to reset completely
 */
function resetFile(file: MemFsEditorFile): void;

/**
 * Clear file state by moving current state to stateCleared
 * @param file - The file object to clear state for
 */
function clearFileState(file: MemFsEditorFile): void;

State Query Functions

Check for the presence of state properties on file objects.

/**
 * Check if a file has any state property set
 * @param file - The file object to check
 * @returns True if file has a state property
 */
function hasState(file: MemFsEditorFile): boolean;

/**
 * Check if a file has a cleared state property
 * @param file - The file object to check
 * @returns True if file has a stateCleared property
 */
function hasClearedState(file: MemFsEditorFile): boolean;

Usage Examples

import { 
  setFileState, 
  isFileNew, 
  isFileStateModified,
  setModifiedFileState,
  isFilePending,
  resetFile
} from "mem-fs-editor/state";
import { create as createMemFs } from "mem-fs";
import { create as createEditor } from "mem-fs-editor";

const store = createMemFs();
const fs = createEditor(store);

// Write a file and check its state
fs.write("example.txt", "Hello World");
const file = store.get("example.txt");

// Check if file is new
console.log(isFileNew(file)); // true (doesn't exist on disk yet)

// File is automatically marked as modified when written
console.log(isFileStateModified(file)); // true

// Check if file has pending changes
console.log(isFilePending(file)); // true

// After committing, the file state changes
await fs.commit();
console.log(isFilePending(file)); // false

// Manually manage file states
const anotherFile = store.get("another.txt");
setModifiedFileState(anotherFile);

// Clean up all states when done
resetFile(file);

State Lifecycle

Files in mem-fs-editor follow this state lifecycle:

  1. New File: isNew: true when file doesn't exist on disk
  2. Modified: state: 'modified' when file contents change
  3. Deleted: state: 'deleted' when file is marked for deletion
  4. Committed: committed: true after successful commit to disk
  5. Cleared: stateCleared: 'modified'|'deleted' when state is cleared but preserved

The state management functions allow you to query and manipulate files at any point in this lifecycle, providing fine-grained control over file operations and commit behavior.

docs

commit-pipeline.md

file-copy.md

file-management.md

file-reading.md

file-writing.md

index.md

state-management.md

template-processing.md

transform.md

tile.json