memfs icon indicating copy to clipboard operation
memfs copied to clipboard

feat: add comprehensive FileSystem observer API types with full MDN spec compliance

Open Copilot opened this issue 4 months ago • 1 comments

Added complete TypeScript type definitions for the File System Access API observer interfaces to src/fsa/types.ts, implementing the full MDN specification.

New Types Added

FileSystemChangeRecord

Represents a file system change event with comprehensive properties:

  • changedHandle: IFileSystemHandle | IFileSystemSyncAccessHandle | null - The changed file system handle (null for "disappeared", "errored", or "unknown" types)
  • relativePathComponents: string[] - Path components from the observed directory to the changed handle
  • relativePathMovedFrom: string[] | null - Former location path for "moved" type events
  • root: IFileSystemHandle | IFileSystemSyncAccessHandle - Reference to the root handle passed to observe()
  • type: 'appeared' | 'disappeared' | 'modified' | 'moved' | 'errored' | 'unknown' - Complete set of change types

IFileSystemObserver

Observer interface with constructor signature and methods:

  • Constructor with callback function (records, observer) => void
  • observe(handle, options?) - Start observing changes to a directory handle
  • unobserve(handle) - Stop observing changes to a specific directory handle
  • disconnect() - Disconnect and stop all observations

FileSystemObserverObserveOptions

Options interface for the observe method:

  • recursive?: boolean - Whether to observe changes recursively in subdirectories

Implementation Details

  • Full compliance with MDN File System Access API specification
  • Support for both user-observable file system and Origin Private File System (OPFS) with IFileSystemSyncAccessHandle
  • Proper nullable types for handles based on event types
  • Complete JSDoc documentation with MDN references
  • Constructor typing enables proper instantiation: new FileSystemObserver(callback)

These types enable future implementation of file system watching functionality for the watchFile, unwatchFile, and watch methods in FsaNodeFs.

Fixes #1170.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot avatar Aug 22 '25 16:08 Copilot

@copilot pls

streamich avatar Aug 22 '25 21:08 streamich