npm.io
0.2.0 • Published 1 week ago

@xfcfam/xf-fs

Licence
MIT
Version
0.2.0
Deps
0
Size
117 kB
Vulns
0
Weekly
0

@xfcfam/xf-fs

Filesystem Access Generalization for the XF Architecture Modelnode:fs behind one coherent, XF-compliant FileRepository.

For React Native, @xfcfam/xf-reactnative-fs exposes the same API (and re-uses these Transfer types) over the device filesystem instead of node:fs.

Install

npm i @xfcfam/xf @xfcfam/xf-fs

Quick start

import { FileRepository } from '@xfcfam/xf-fs'

export class UsersFileRepository extends FileRepository {
  constructor() { super({ rootPath: '/var/data/users' }) }
  async findById(id: string) { return JSON.parse(await this.read(`${id}.json`)) }
  async save(u: User) { await this.write(`${u.id}.json`, JSON.stringify(u)) }
}

Exported Components

Generalizations
Component Description
FileRepository The whole local-filesystem protocol over node:fs. Returns FileStat / FileEntry, hands back Watcher / TempFile handles, and raises typed FileNotFoundException / FileAccessDeniedException / DirectoryNotEmptyException.
CachedFileRepository Adds a write-through in-memory cache over read / readBytes.
AuditedFileRepository Adds an observability policy — every operation fires a hook.
Utilities
Component Description
PathUtils Pure POSIX path manipulation.
EncodingUtils BOM-aware UTF-8 encoding helpers.

Three filesystem errors become typed exceptions — FileNotFoundExceptionENOENT, FileAccessDeniedExceptionEACCES/EPERM, DirectoryNotEmptyExceptionENOTEMPTY. Anything else propagates as native Error.

Documentation

Full specification → xfcfam.org

License

MIT

Keywords