UNPKG

@neodx/vfs

Version:

Simple virtual file system - working dir context, lazy changes, different modes, integrations and moreover

106 lines (102 loc) 3.22 kB
import { B as BaseVfs, V as VfsContentLike, m as VfsPlugin } from '../_internal/types-Bu8eLcj4.js'; import { ParseJsonParams, SerializeJsonParams } from '@neodx/fs'; type FileApi = ReturnType<typeof createFileApi>; declare const createFileApi: ( vfs: BaseVfs, path: string ) => { tryRead: (encoding: BufferEncoding) => Promise<string | null>; read: (encoding: BufferEncoding) => Promise<string>; write: (content: VfsContentLike) => Promise<void>; rename: (...args: string[]) => Promise<void>; exists: () => Promise<boolean>; delete: () => Promise<void>; path: string; }; interface JsonPluginApi { jsonFile<FileContents extends JSONValue | unknown = unknown>( path: string ): JsonFileApi<FileContents>; readJson<T extends JSONValue | unknown = unknown>( path: string, options?: ParseJsonParams ): Promise<T>; writeJson<T extends JSONValue | unknown = unknown>( path: string, json: T, options?: SerializeJsonParams ): Promise<void>; updateJson<T extends JSONValue | unknown = unknown>( path: string, updater: JsonUpdate<T>, options?: ParseJsonParams & SerializeJsonParams ): Promise<void>; } interface JsonFileApi<FileContents extends JSONValue | unknown = unknown> extends Omit<FileApi, 'read' | 'write' | 'tryRead'> { tryRead<T extends FileContents = FileContents>(options?: ParseJsonParams): Promise<T | null>; read<T extends FileContents = FileContents>(options?: ParseJsonParams): Promise<T>; write<T extends FileContents = FileContents>( json: T, options?: SerializeJsonParams ): Promise<void>; update<T extends FileContents = FileContents>( updater: JsonUpdate<T>, options?: ParseJsonParams & SerializeJsonParams ): Promise<void>; /** * @todo Implement "resources" and streaming APIs * @deprecated Unstable API */ experimental_toResource( defaultValue: FileContents, options?: ParseJsonParams & SerializeJsonParams ): Promise< { data: FileContents; } & AsyncDisposable >; } type JsonUpdate<T> = (json: T) => T | void | Promise<T | void>; declare function json(): VfsPlugin<JsonPluginApi>; declare function createJsonFileApi<FileContents extends JSONValue | unknown = unknown>( vfs: BaseVfs, path: string ): JsonFileApi<FileContents>; declare function readVfsJson<T extends JSONValue | unknown = unknown>( vfs: BaseVfs, path: string, options?: ParseJsonParams ): Promise<T>; declare function writeVfsJson<T extends JSONValue | unknown = unknown>( vfs: BaseVfs, path: string, json: T, options?: SerializeJsonParams ): Promise<void>; declare function updateVfsJson<T extends JSONValue | unknown = unknown>( vfs: BaseVfs, path: string, updater: JsonUpdate<T>, options?: ParseJsonParams & SerializeJsonParams ): Promise<void>; type JSONPrimitive = string | number | boolean | null; type JSONValue = JSONPrimitive | JSONObject | JSONArray; type JSONArray = JSONValue[]; interface JSONObject { [member: string]: JSONValue; } export { type JSONArray, type JSONObject, type JSONPrimitive, type JSONValue, type JsonFileApi, type JsonPluginApi, type JsonUpdate, createJsonFileApi, json, readVfsJson, updateVfsJson, writeVfsJson };