@zthun/crumbtrail-fs 2.4.5 → 2.4.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -183,7 +183,6 @@ function _define_property$2(obj, key, value) {
183
183
  async stop() {
184
184
  await this._watcher?.close();
185
185
  delete this._watcher;
186
- return Promise.resolve();
187
186
  }
188
187
  add() {
189
188
  return this._add.asObservable();
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../src/file-system/file-system-node.mts","../src/file-system/file-system-service.mts","../src/file-watch/file-watch.mts","../src/file-repository/file-repository.mts","../src/resolve-path-like/resolve-path-like.ts","../src/sleep-watch-delay/sleep-watch-delay.mts","../src/stream/stream-folder.mts","../src/stream/stream-file.mts"],"sourcesContent":["import { type ZMutable } from \"@zthun/helpful-fn\";\nimport { isUndefined, omitBy } from \"lodash-es\";\nimport type { Stats } from \"node:fs\";\nimport { basename, dirname, extname } from \"node:path\";\n\n/**\n * Represents a type of a file system node.\n */\nexport enum ZFileSystemNodeType {\n File = \"file\",\n Folder = \"folder\",\n}\n\nexport interface IZFileSystemNode {\n /**\n * The absolute path of the node.\n */\n path: string;\n\n /**\n * The type of the node (file or folder).\n */\n type: ZFileSystemNodeType;\n\n /**\n * The creation date of the node.\n */\n created?: string;\n\n /**\n * The modification date of the node.\n */\n updated?: string;\n\n /**\n * The size of the node in bytes.\n */\n size?: bigint;\n\n /**\n * The file or folder name with the extension.\n *\n * Calculated from the path.\n */\n readonly name: string;\n\n /**\n * The file extension.\n *\n * Calculated from the path.\n */\n readonly extension: string;\n\n /**\n * File title.\n *\n * The name without the extension.\n * Calculated from the path.\n */\n readonly title: string;\n\n /**\n * Parent directory path.\n */\n readonly parent: string;\n}\n\n/**\n * Represents a builder for a file system node.\n */\nexport class ZFileSystemNodeBuilder {\n private _node: ZMutable<IZFileSystemNode> = {\n path: \"/\",\n type: ZFileSystemNodeType.Folder,\n extension: \"\",\n name: \"\",\n parent: \"\",\n title: \"\",\n };\n\n public created(at?: Date | string | undefined) {\n this._node.created = at instanceof Date ? at.toJSON() : at;\n\n return this;\n }\n\n public updated(at?: Date | string | undefined) {\n this._node.updated = at instanceof Date ? at.toJSON() : at;\n\n return this;\n }\n\n public size(bytes: bigint | number | undefined) {\n this._node.size = typeof bytes == \"number\" ? BigInt(bytes) : bytes;\n\n return this;\n }\n\n public path(path: string) {\n this._node.path = path;\n\n return this.decorate();\n }\n\n public type(type: ZFileSystemNodeType) {\n this._node.type = type;\n\n return this.decorate();\n }\n\n public file = this.type.bind(this, ZFileSystemNodeType.File);\n public folder = this.type.bind(this, ZFileSystemNodeType.Folder);\n\n public stats(s: Stats) {\n const builder = this.size(s.size).created(s.birthtime).updated(s.mtime);\n\n return s.isFile() ? builder.file() : builder.folder();\n }\n\n public build() {\n const clone = structuredClone(this._node);\n\n return omitBy(clone, isUndefined) as IZFileSystemNode;\n }\n\n private decorate() {\n const { path, type } = this._node;\n\n this._node.name = basename(path);\n this._node.extension = \"\";\n this._node.title = this._node.name;\n this._node.parent = dirname(path);\n\n if (type === ZFileSystemNodeType.File) {\n const extension = extname(path);\n this._node.extension = extension;\n this._node.title = basename(path, extension);\n }\n\n if (!path || path === \"/\" || this._node.parent === \".\") {\n this._node.parent = \"\";\n }\n\n return this;\n }\n}\n","import { glob } from \"glob\";\nimport { access } from \"node:fs/promises\";\nimport { dirname, isAbsolute, resolve } from \"node:path\";\nimport { cwd } from \"node:process\";\nimport type { IZFileSystemNode } from \"./file-system-node.mjs\";\nimport { ZFileSystemNodeBuilder } from \"./file-system-node.mjs\";\n\n/**\n * Represents options for searches.\n */\nexport interface IZFileSystemSearchOptions {\n /**\n * The directory to search in.\n *\n * If this is not set, then the cwd of the application is used.\n */\n cwd?: string;\n\n /**\n * A flag that determines whether or not to load the\n * file system information.\n *\n * This is true by default.\n */\n stat?: boolean;\n}\n\n/**\n * Represents options for directory walking.\n */\nexport interface IZFileSystemWalkOptions {\n /**\n * The starting directory.\n *\n * The default is the current working directory\n *\n * @see process.cwd for more information.\n */\n start?: string;\n\n /**\n * The directory to stop at.\n *\n * The default is the root of the file system.\n */\n stop?: string;\n\n /**\n * The type of mode that the path must support in order\n * to be approved.\n *\n * The default is undefined and left up to the node api.\n */\n mode?: number;\n}\n\n/**\n * Represents a service to enumerate the file system.\n */\nexport interface IZFileSystemService {\n /**\n * Gets information about a node.\n *\n * @param path -\n * The path to get information for.\n *\n * @returns\n * Information about the node.\n */\n info(path: string): Promise<IZFileSystemNode>;\n\n /**\n * Reads all nodes that match a pattern.\n *\n * @param pattern -\n * The pattern string to match against or a list\n * of patterns to match.\n * @param options -\n * The options for the search.\n *\n * @returns\n * A list of path strings that match the given patterns.\n */\n search(\n pattern: string | string[],\n options?: IZFileSystemSearchOptions,\n ): Promise<IZFileSystemNode[]>;\n\n /**\n * Walks up a directory tree to search for existence of a given path.\n *\n * @param search -\n * The path to search for. This is the candidate folder path that\n * may or may not exist somewhere from the start directory all the\n * way up the directory tree.\n * @param options -\n * The given options for the search.\n *\n * @returns\n * The fully qualified path to the first path that matches the search\n * starting at the options start or the current working directory if not\n * specified. Returns null if no such directory exists.\n *\n * @example\n *\n * ```ts\n * import { resolve } from 'path'\n *\n * // Find any folder named .vscode from the current working directory all the way\n * // up the directory tree. Returns null if no vscode directory can be found.\n * const service = new ZFileSystemService();\n * const vscode = service.walk('.vscode');\n *\n * // Walk the directory tree from the current script and find the .config folder.\n * const config = service.walk('.config', { start: __dirname });\n *\n * // Walk the directory tree from the current script and stop when we reach\n * // at most 2 directories up.\n * const start = __dirname;\n * const stop = resolve(__dirname, '../..');\n * const file = service.walk('path/to/file.json', { start, stop });\n * ```\n */\n walk(\n search: string,\n options?: IZFileSystemWalkOptions,\n ): Promise<string | null>;\n}\n\n/**\n * Represents a node implementation of a file system service.\n */\nexport class ZFileSystemService implements IZFileSystemService {\n public async info(path: string): Promise<IZFileSystemNode> {\n const [file] = await this.search(path);\n return file;\n }\n\n public async search(\n pattern: string | string[],\n options?: IZFileSystemSearchOptions,\n ): Promise<IZFileSystemNode[]> {\n const paths = await glob(pattern, {\n stat: true,\n ...options,\n withFileTypes: true,\n });\n\n return paths.map((path) => {\n let info = new ZFileSystemNodeBuilder()\n .path(path.fullpath())\n .created(path.birthtime)\n .updated(path.atime)\n .size(path.size);\n\n // Note that for folders, node will return the size of the underlying OS metadata,\n // hence, why we remove the size on the folder here.\n info = path.isFile() ? info.file() : info.folder().size(undefined);\n\n return info.build();\n });\n }\n\n public async walk(search: string, options?: IZFileSystemWalkOptions) {\n const start = options?.start || cwd();\n const stop = options?.stop || \"/\";\n const mode = options?.mode;\n\n const _test = async (path: string) => {\n try {\n await access(path, mode);\n return true;\n } catch {\n return false;\n }\n };\n\n if (isAbsolute(search)) {\n return (await _test(search)) ? search : null;\n }\n\n let dir = start;\n do {\n const path = resolve(dir, search);\n const exists = await _test(path);\n\n if (exists) {\n return path;\n }\n\n dir = dir === stop ? \"\" : dirname(dir);\n } while (dir.length);\n\n return null;\n }\n}\n","import type { FSWatcher } from \"chokidar\";\nimport { watch } from \"chokidar\";\nimport type { Stats } from \"node:fs\";\nimport { resolve } from \"node:path\";\nimport type { Observable } from \"rxjs\";\nimport { Subject } from \"rxjs\";\nimport {\n ZFileSystemNodeBuilder,\n type IZFileSystemNode,\n} from \"../file-system/file-system-node.mjs\";\n\n/**\n * Represents and object that can watch a folder or file on the file system.\n */\nexport interface IZFileWatch {\n /**\n * Starts the watch operation.\n */\n start(): Promise<void>;\n\n /**\n * Stops the watch operation.\n */\n stop(): Promise<void>;\n\n /**\n * The stream for files being added.\n *\n * This can only occur if the target being watched\n * is a folder.\n *\n * @returns\n * The observable that will publish files that\n * get added.\n */\n add(): Observable<IZFileSystemNode>;\n\n /**\n * The stream for files being updated.\n *\n * If this watcher points to a folder, then all files\n * recursively will send when they get updated. If this\n * watcher points to a file, then this will only invoke\n * when the file is updated.\n *\n * @returns\n * The observable that will publish files and folders\n * that are updated.\n */\n update(): Observable<IZFileSystemNode>;\n\n /**\n * The stream for files and folders being deleted.\n *\n * If this watcher points to a folder, then all files under the\n * folder will be sent through this observable, including the\n * folder being watched. If this points to a file, then\n * this will only receive when the file is unlinked.\n *\n * @returns\n * The observable that will publish file and folders\n * that are unlinked and removed respectively. Note\n * that files and folders streamed this way will not\n * have their stats set.\n */\n remove(): Observable<IZFileSystemNode>;\n}\n\n/**\n * An implementation of the IZFileWatch.\n */\nexport class ZFileWatch implements IZFileWatch {\n private _add: Subject<IZFileSystemNode> = new Subject<IZFileSystemNode>();\n private _update: Subject<IZFileSystemNode> = new Subject<IZFileSystemNode>();\n private _remove: Subject<IZFileSystemNode> = new Subject<IZFileSystemNode>();\n private _watcher: FSWatcher | undefined;\n\n /**\n * Initializes a new instance of this object.\n *\n * @param path -\n * The path to watch.\n */\n public constructor(public readonly path: string) {}\n\n public async start() {\n await this.stop();\n\n this._watcher = watch(this.path, {\n usePolling: true,\n alwaysStat: true,\n ignoreInitial: true,\n\n awaitWriteFinish: {\n stabilityThreshold: 500,\n pollInterval: 50,\n },\n });\n\n function next(\n observable: Subject<IZFileSystemNode>,\n file: string,\n stats: Stats | undefined,\n ) {\n const node = new ZFileSystemNodeBuilder().path(resolve(this.path, file));\n observable.next(stats ? node.stats(stats).build() : node.build());\n }\n\n this._watcher\n .on(\"add\", next.bind(this, this._add))\n .on(\"addDir\", next.bind(this, this._add))\n .on(\"change\", next.bind(this, this._update))\n .on(\"unlink\", next.bind(this, this._remove))\n .on(\"unlinkDir\", next.bind(this, this._remove));\n\n return new Promise<void>((resolve) =>\n this._watcher?.on(\"ready\", () => resolve()),\n );\n }\n\n public async stop() {\n await this._watcher?.close();\n delete this._watcher;\n return Promise.resolve();\n }\n\n public add() {\n return this._add.asObservable();\n }\n\n public update() {\n return this._update.asObservable();\n }\n\n public remove() {\n return this._remove.asObservable();\n }\n}\n","import { firstDefined, sleep } from \"@zthun/helpful-fn\";\nimport type { IZDataRequest, IZDataSource } from \"@zthun/helpful-query\";\nimport { ZDataSourceStatic } from \"@zthun/helpful-query\";\nimport { find, findIndex, flatten, trimEnd, uniqBy } from \"lodash-es\";\nimport { minimatch } from \"minimatch\";\nimport { resolve, sep } from \"node:path\";\nimport type { Subscription } from \"rxjs\";\nimport {\n ZFileSystemNodeType,\n type IZFileSystemNode,\n} from \"../file-system/file-system-node.mjs\";\nimport {\n ZFileSystemService,\n type IZFileSystemService,\n} from \"../file-system/file-system-service.mjs\";\nimport { ZFileWatch, type IZFileWatch } from \"../file-watch/file-watch.mjs\";\n\n/**\n * Represents a repository for the file system.\n */\nexport interface IZFileRepository extends IZDataSource<IZFileSystemNode> {\n /**\n * Retrieves a single file from the repository.\n *\n * @param path -\n * The fully qualified path to the file.\n *\n * @returns\n * The node that represents the file. Returns null if no\n * such file exists.\n */\n get(path: string): Promise<IZFileSystemNode | null>;\n}\n\n/**\n * Represents an implementation of a ZFileRepository that watches\n * a given path scope.\n *\n * This repository is only concerned about files. Folders\n * will not be retrieved from this repository.\n */\nexport class ZFileRepository implements IZFileRepository {\n private _service: IZFileSystemService = new ZFileSystemService();\n private _watcher: IZFileWatch | undefined;\n private _nodes: Promise<ZDataSourceStatic<IZFileSystemNode>> =\n Promise.resolve(new ZDataSourceStatic<IZFileSystemNode>([]));\n private _globs: string[] = [\"**\"];\n private _path: string = \"\";\n private _add: Subscription | undefined;\n private _remove: Subscription | undefined;\n private _update: Subscription | undefined;\n\n /**\n * Gets the path that this repository is watching.\n */\n public get path() {\n return this._path;\n }\n\n /**\n * Gets the globs matchers that this repository is matching against.\n */\n public get globs() {\n return this._globs.slice();\n }\n\n /**\n * Initializes the repository with the given root and glob filter.\n *\n * This will initially scan the file system and setup watches.\n * If you call this method again, then the repository will be\n * {@link reset} and a new set of files will be added to the\n * repository.\n *\n * @param path -\n * The root path of the repository.\n * @param globs -\n * The optional relative globs of the repository. If this is falsy,\n * then ** is used. You can achieve the same kind of operation\n * using filters, but filtering out unwanted files frees up the internal\n * memory being used.\n */\n public async initialize(path: string, globs: string[] = [\"**\"]) {\n await this.reset();\n\n this._path = path;\n this._globs = globs;\n\n // Note that this all happens in the background and should\n // only be awaited later. So the search should not be\n // required to finish when existing this method. The only\n // requirement is that the repository is reset and the path +\n // glob scope is updated. Everything beyond here should not\n // be awaited - it will be awaited later once the caller\n // tries to retrieve the files using retrieve, get, or\n // count.\n const matches = globs.map((g) =>\n this._service.search(g, {\n cwd: path,\n stat: true,\n }),\n );\n\n this._nodes = Promise.all(matches)\n .then((nodes) => {\n const flat = flatten(nodes);\n const uniq = uniqBy(flat, (n) => n.path);\n return uniq.filter((n) => n.type === ZFileSystemNodeType.File);\n })\n .then((files) => {\n return new ZDataSourceStatic(files);\n });\n\n this._watcher = new ZFileWatch(path);\n\n this._add = this._watcher\n .add()\n .subscribe(async (node: IZFileSystemNode) => {\n if (\n node.type === ZFileSystemNodeType.File &&\n this._globs.some((g) => minimatch(node.path, resolve(this._path, g)))\n ) {\n const nodes = await this._nodes;\n this._nodes = nodes.insert(node);\n }\n });\n\n this._remove = this._watcher\n .remove()\n .subscribe(async (node: IZFileSystemNode) => {\n let nodes = await this._nodes;\n const path = trimEnd(node.path, sep);\n\n // It's possible that the node given was a folder. If that happens,\n // we need to remove all files that start with the given path.\n // If the node does point to a file, then there is no possibility that\n // more than 1 item would be removed.\n\n const next = async () =>\n findIndex(await nodes.items(), (n) => {\n return (\n n.path === path ||\n (n.path.startsWith(path) &&\n n.path.substring(path.length).charAt(0) === sep)\n );\n });\n\n for (let index = await next(); index >= 0; index = await next()) {\n nodes = await nodes.removeAt(index);\n }\n\n this._nodes = Promise.resolve(nodes);\n });\n\n this._update = this._watcher\n .update()\n .subscribe(async (node: IZFileSystemNode) => {\n const nodes = await this._nodes;\n const index = findIndex(\n await nodes.items(),\n (n) => n.path === node.path,\n );\n\n // It's possible node was filtered out by the globs, or\n // it is a directory. If so, then we won't have it in our\n // list.\n if (index >= 0) {\n const next = await nodes.removeAt(index);\n this._nodes = next.insert(node, index);\n }\n });\n\n // Kick off the initial seed operation with an even loop\n // invocation.\n await sleep(100);\n\n await this._watcher?.start();\n }\n\n /**\n * Resets the repository as if it was initially created.\n */\n public async reset(): Promise<void> {\n await this._watcher?.stop();\n\n this._add?.unsubscribe();\n this._remove?.unsubscribe();\n this._update?.unsubscribe();\n\n delete this._add;\n delete this._remove;\n delete this._update;\n delete this._watcher;\n\n this._path = \"\";\n this._globs = [\"**\"];\n this._nodes = Promise.resolve(new ZDataSourceStatic<IZFileSystemNode>([]));\n }\n\n public async get(path: string): Promise<IZFileSystemNode | null> {\n const nodes = await this._nodes;\n const items = await nodes.items();\n const node = find(items, (f) => f.path === path);\n\n return firstDefined(null, node);\n }\n\n public async count(request: IZDataRequest): Promise<number> {\n const source = await this._nodes;\n return source.count(request);\n }\n\n public async retrieve(request: IZDataRequest): Promise<IZFileSystemNode[]> {\n const source = await this._nodes;\n return source.retrieve(request);\n }\n}\n","import type { PathLike } from \"node:fs\";\nimport { resolve } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\n\nexport function resolvePathLike(path: PathLike): string {\n if (typeof path === \"string\") {\n return resolve(path);\n }\n\n if (path instanceof URL) {\n return fileURLToPath(path);\n }\n\n return resolve(path.toString());\n}\n","import { sleep } from \"@zthun/helpful-fn\";\n\n/**\n * The actual delay time that you should wait for a watch\n * operation to pick up your file changes.\n */\nexport const ZWatchDelay = 1500;\n\n/**\n * Performs a sleep long enough to allow a watch operation\n * to pick up a change.\n *\n * You should never really need this. Where it is useful\n * is for unit testing with IO operations and you want to\n * wait for your write operations to get picked up by\n * a file watch operation.\n */\nexport function sleepWatchDelay() {\n return sleep(ZWatchDelay);\n}\n","import type { PathLike } from \"fs\";\nimport { mkdir } from \"fs/promises\";\nimport type { IZStreamWrite } from \"./stream-write.mjs\";\n\n/**\n * A stream that writes folders.\n *\n * Writing folders is idempotent. If the folder you\n * are trying to write already exists, then the write\n * operation still succeeds\n */\nexport class ZStreamFolder implements IZStreamWrite {\n public async write(path: PathLike): Promise<number> {\n await mkdir(path, { recursive: true });\n\n return 0;\n }\n}\n","import type { PathLike, Stats } from \"node:fs\";\nimport { readFile, stat, writeFile } from \"node:fs/promises\";\nimport { dirname } from \"path\";\nimport { resolvePathLike } from \"../resolve-path-like/resolve-path-like.js\";\nimport { ZStreamFolder } from \"./stream-folder.mjs\";\nimport type { IZStreamRead, IZStreamReadOptions } from \"./stream-read.mjs\";\nimport type { IZStreamWrite, IZStreamWriteOptions } from \"./stream-write.mjs\";\n\n/**\n * Options for the stream file object.\n */\nexport interface IZStreamFileOptions {\n /**\n * Cache options.\n *\n * A warning that file content caching will take up significant memory\n * if the file size is too big or the max files is too big. Make sure\n * you know what you're doing when you change the default values of this.\n */\n cache?: {\n /**\n * Maximum number of bytes a file can be before it will not be cached.\n * The default is 100 Kib (102400 bytes)\n *\n * @default 102400\n */\n fileSize?: bigint;\n /**\n * The maximum number of files that are to be cached. The cache order\n * is first in, first out. Set this to 0 to not cache anything. The\n * default is 1000.\n *\n * @default 1000\n */\n maxFiles?: number;\n };\n}\n\n/**\n * A stream that can read and write to files.\n *\n * This is mostly a wrapper to readFile and writeFile from node, but\n * with some optimizations.\n *\n * First, this class supports file content caching so reading in a file\n * that's under a certain size threshold will store it in memory for\n * later retrieval.\n */\nexport class ZStreamFile implements IZStreamWrite, IZStreamRead {\n private static readonly FileSizeDefault = 102400; // One Hundred KibiBytes\n private static readonly MaxFilesDefault = 1000;\n\n private _cache = new Map<string, { stats: Stats; buffer: Promise<Buffer> }>();\n\n /**\n * Initializes a new instance of this object.\n *\n * @param options -\n * The options for file read and writes.\n */\n public constructor(public readonly options: IZStreamFileOptions = {}) {}\n\n public async read(\n path: PathLike,\n options?: IZStreamReadOptions,\n ): Promise<Buffer> {\n const _path = resolvePathLike(path);\n\n const stats = await stat(_path);\n const cached = this._cache.get(_path);\n\n const buffer =\n cached && cached.stats.mtimeMs >= stats.mtimeMs\n ? cached.buffer\n : readFile(_path, options);\n\n return this._addToCache(_path, { stats, buffer });\n }\n\n public async write(\n path: PathLike,\n { buffer = Buffer.from(\"\") }: IZStreamWriteOptions = {},\n ): Promise<number> {\n const _path = resolvePathLike(path);\n const directory = dirname(_path);\n\n await new ZStreamFolder().write(directory);\n await writeFile(_path, buffer, { flush: true });\n\n // If this file specifically was cached earlier,\n // we can just remove it now so we make room for\n // another file. Consumers can just read the\n // file again to recache it.\n this._cache.delete(_path);\n\n return buffer.length;\n }\n\n private _addToCache(\n path: string,\n item: { stats: Stats; buffer: Promise<Buffer> },\n ) {\n const { cache = {} } = this.options;\n const {\n fileSize = ZStreamFile.FileSizeDefault,\n maxFiles = ZStreamFile.MaxFilesDefault,\n } = cache;\n\n if (item.stats.size > fileSize) {\n // In this case, the file size is too big to cache in memory,\n // so we're bowing out here.\n return item.buffer;\n }\n\n // We will remove this path from the cache first since\n // we want it to be the most recent file (at the end)\n // of the key list. The removal does nothing if the\n // file was not cached.\n this._cache.delete(path);\n this._cache.set(path, item);\n\n if (this._cache.size > maxFiles) {\n // Retrieving the keys from a javascript map is order\n // by the time in which the keys are created. So\n // we are going to remove the first key which is the\n // oldest.\n const itr = this._cache.keys();\n this._cache.delete(itr.next().value);\n }\n\n return item.buffer;\n }\n}\n"],"names":["ZFileSystemNodeType","ZFileSystemNodeBuilder","created","at","_node","Date","toJSON","updated","size","bytes","BigInt","path","decorate","type","stats","s","builder","birthtime","mtime","isFile","file","folder","build","clone","structuredClone","omitBy","isUndefined","name","basename","extension","title","parent","dirname","extname","_define_property","bind","ZFileSystemService","info","search","pattern","options","paths","glob","stat","withFileTypes","map","fullpath","atime","undefined","walk","start","cwd","stop","mode","_test","access","isAbsolute","dir","resolve","exists","length","ZFileWatch","_watcher","watch","usePolling","alwaysStat","ignoreInitial","awaitWriteFinish","stabilityThreshold","pollInterval","next","observable","node","on","_add","_update","_remove","Promise","close","add","asObservable","update","remove","Subject","ZFileRepository","_path","globs","_globs","slice","initialize","reset","matches","g","_service","_nodes","all","then","nodes","flat","flatten","uniq","uniqBy","n","filter","File","files","ZDataSourceStatic","subscribe","some","minimatch","insert","trimEnd","sep","findIndex","items","startsWith","substring","charAt","index","removeAt","sleep","unsubscribe","get","find","f","firstDefined","count","request","source","retrieve","resolvePathLike","URL","fileURLToPath","toString","ZWatchDelay","sleepWatchDelay","ZStreamFolder","write","mkdir","recursive","ZStreamFile","read","cached","_cache","buffer","mtimeMs","readFile","_addToCache","Buffer","from","directory","writeFile","flush","delete","item","cache","fileSize","FileSizeDefault","maxFiles","MaxFilesDefault","set","itr","keys","value","Map"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKA;;IAGO,IAAKA,mBAAAA,iBAAAA,SAAAA,mBAAAA,EAAAA;;;AAAAA,IAAAA,OAAAA,mBAAAA;AAGX,CAAA,CAAA,EAAA;AAwDD;;AAEC,IACM,MAAMC,sBAAAA,CAAAA;AAUJC,IAAAA,OAAAA,CAAQC,EAA8B,EAAE;QAC7C,IAAI,CAACC,KAAK,CAACF,OAAO,GAAGC,EAAAA,YAAcE,IAAAA,GAAOF,EAAAA,CAAGG,MAAM,EAAA,GAAKH,EAAAA;AAExD,QAAA,OAAO,IAAI;AACb,IAAA;AAEOI,IAAAA,OAAAA,CAAQJ,EAA8B,EAAE;QAC7C,IAAI,CAACC,KAAK,CAACG,OAAO,GAAGJ,EAAAA,YAAcE,IAAAA,GAAOF,EAAAA,CAAGG,MAAM,EAAA,GAAKH,EAAAA;AAExD,QAAA,OAAO,IAAI;AACb,IAAA;AAEOK,IAAAA,IAAAA,CAAKC,KAAkC,EAAE;QAC9C,IAAI,CAACL,KAAK,CAACI,IAAI,GAAG,OAAOC,KAAAA,IAAS,QAAA,GAAWC,MAAAA,CAAOD,KAAAA,CAAAA,GAASA,KAAAA;AAE7D,QAAA,OAAO,IAAI;AACb,IAAA;AAEOE,IAAAA,IAAAA,CAAKA,IAAY,EAAE;AACxB,QAAA,IAAI,CAACP,KAAK,CAACO,IAAI,GAAGA,IAAAA;QAElB,OAAO,IAAI,CAACC,QAAQ,E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","../src/file-system/file-system-service.mts","../src/file-watch/file-watch.mts","../src/file-repository/file-repository.mts","../src/resolve-path-like/resolve-path-like.ts","../src/sleep-watch-delay/sleep-watch-delay.mts","../src/stream/stream-folder.mts","../src/stream/stream-file.mts"],"sourcesContent":["import { type ZMutable } from \"@zthun/helpful-fn\";\nimport { isUndefined, omitBy } from \"lodash-es\";\nimport type { Stats } from \"node:fs\";\nimport { basename, dirname, extname } from \"node:path\";\n\n/**\n * Represents a type of a file system node.\n */\nexport enum ZFileSystemNodeType {\n File = \"file\",\n Folder = \"folder\",\n}\n\nexport interface IZFileSystemNode {\n /**\n * The absolute path of the node.\n */\n path: string;\n\n /**\n * The type of the node (file or folder).\n */\n type: ZFileSystemNodeType;\n\n /**\n * The creation date of the node.\n */\n created?: string;\n\n /**\n * The modification date of the node.\n */\n updated?: string;\n\n /**\n * The size of the node in bytes.\n */\n size?: bigint;\n\n /**\n * The file or folder name with the extension.\n *\n * Calculated from the path.\n */\n readonly name: string;\n\n /**\n * The file extension.\n *\n * Calculated from the path.\n */\n readonly extension: string;\n\n /**\n * File title.\n *\n * The name without the extension.\n * Calculated from the path.\n */\n readonly title: string;\n\n /**\n * Parent directory path.\n */\n readonly parent: string;\n}\n\n/**\n * Represents a builder for a file system node.\n */\nexport class ZFileSystemNodeBuilder {\n private _node: ZMutable<IZFileSystemNode> = {\n path: \"/\",\n type: ZFileSystemNodeType.Folder,\n extension: \"\",\n name: \"\",\n parent: \"\",\n title: \"\",\n };\n\n public created(at?: Date | string | undefined) {\n this._node.created = at instanceof Date ? at.toJSON() : at;\n\n return this;\n }\n\n public updated(at?: Date | string | undefined) {\n this._node.updated = at instanceof Date ? at.toJSON() : at;\n\n return this;\n }\n\n public size(bytes: bigint | number | undefined) {\n this._node.size = typeof bytes == \"number\" ? BigInt(bytes) : bytes;\n\n return this;\n }\n\n public path(path: string) {\n this._node.path = path;\n\n return this.decorate();\n }\n\n public type(type: ZFileSystemNodeType) {\n this._node.type = type;\n\n return this.decorate();\n }\n\n public file = this.type.bind(this, ZFileSystemNodeType.File);\n public folder = this.type.bind(this, ZFileSystemNodeType.Folder);\n\n public stats(s: Stats) {\n const builder = this.size(s.size).created(s.birthtime).updated(s.mtime);\n\n return s.isFile() ? builder.file() : builder.folder();\n }\n\n public build() {\n const clone = structuredClone(this._node);\n\n return omitBy(clone, isUndefined) as IZFileSystemNode;\n }\n\n private decorate() {\n const { path, type } = this._node;\n\n this._node.name = basename(path);\n this._node.extension = \"\";\n this._node.title = this._node.name;\n this._node.parent = dirname(path);\n\n if (type === ZFileSystemNodeType.File) {\n const extension = extname(path);\n this._node.extension = extension;\n this._node.title = basename(path, extension);\n }\n\n if (!path || path === \"/\" || this._node.parent === \".\") {\n this._node.parent = \"\";\n }\n\n return this;\n }\n}\n","import { glob } from \"glob\";\nimport { access } from \"node:fs/promises\";\nimport { dirname, isAbsolute, resolve } from \"node:path\";\nimport { cwd } from \"node:process\";\nimport type { IZFileSystemNode } from \"./file-system-node.mjs\";\nimport { ZFileSystemNodeBuilder } from \"./file-system-node.mjs\";\n\n/**\n * Represents options for searches.\n */\nexport interface IZFileSystemSearchOptions {\n /**\n * The directory to search in.\n *\n * If this is not set, then the cwd of the application is used.\n */\n cwd?: string;\n\n /**\n * A flag that determines whether or not to load the\n * file system information.\n *\n * This is true by default.\n */\n stat?: boolean;\n}\n\n/**\n * Represents options for directory walking.\n */\nexport interface IZFileSystemWalkOptions {\n /**\n * The starting directory.\n *\n * The default is the current working directory\n *\n * @see process.cwd for more information.\n */\n start?: string;\n\n /**\n * The directory to stop at.\n *\n * The default is the root of the file system.\n */\n stop?: string;\n\n /**\n * The type of mode that the path must support in order\n * to be approved.\n *\n * The default is undefined and left up to the node api.\n */\n mode?: number;\n}\n\n/**\n * Represents a service to enumerate the file system.\n */\nexport interface IZFileSystemService {\n /**\n * Gets information about a node.\n *\n * @param path -\n * The path to get information for.\n *\n * @returns\n * Information about the node.\n */\n info(path: string): Promise<IZFileSystemNode>;\n\n /**\n * Reads all nodes that match a pattern.\n *\n * @param pattern -\n * The pattern string to match against or a list\n * of patterns to match.\n * @param options -\n * The options for the search.\n *\n * @returns\n * A list of path strings that match the given patterns.\n */\n search(\n pattern: string | string[],\n options?: IZFileSystemSearchOptions,\n ): Promise<IZFileSystemNode[]>;\n\n /**\n * Walks up a directory tree to search for existence of a given path.\n *\n * @param search -\n * The path to search for. This is the candidate folder path that\n * may or may not exist somewhere from the start directory all the\n * way up the directory tree.\n * @param options -\n * The given options for the search.\n *\n * @returns\n * The fully qualified path to the first path that matches the search\n * starting at the options start or the current working directory if not\n * specified. Returns null if no such directory exists.\n *\n * @example\n *\n * ```ts\n * import { resolve } from 'path'\n *\n * // Find any folder named .vscode from the current working directory all the way\n * // up the directory tree. Returns null if no vscode directory can be found.\n * const service = new ZFileSystemService();\n * const vscode = service.walk('.vscode');\n *\n * // Walk the directory tree from the current script and find the .config folder.\n * const config = service.walk('.config', { start: __dirname });\n *\n * // Walk the directory tree from the current script and stop when we reach\n * // at most 2 directories up.\n * const start = __dirname;\n * const stop = resolve(__dirname, '../..');\n * const file = service.walk('path/to/file.json', { start, stop });\n * ```\n */\n walk(\n search: string,\n options?: IZFileSystemWalkOptions,\n ): Promise<string | null>;\n}\n\n/**\n * Represents a node implementation of a file system service.\n */\nexport class ZFileSystemService implements IZFileSystemService {\n public async info(path: string): Promise<IZFileSystemNode> {\n const [file] = await this.search(path);\n return file;\n }\n\n public async search(\n pattern: string | string[],\n options?: IZFileSystemSearchOptions,\n ): Promise<IZFileSystemNode[]> {\n const paths = await glob(pattern, {\n stat: true,\n ...options,\n withFileTypes: true,\n });\n\n return paths.map((path) => {\n let info = new ZFileSystemNodeBuilder()\n .path(path.fullpath())\n .created(path.birthtime)\n .updated(path.atime)\n .size(path.size);\n\n // Note that for folders, node will return the size of the underlying OS metadata,\n // hence, why we remove the size on the folder here.\n info = path.isFile() ? info.file() : info.folder().size(undefined);\n\n return info.build();\n });\n }\n\n public async walk(search: string, options?: IZFileSystemWalkOptions) {\n const start = options?.start || cwd();\n const stop = options?.stop || \"/\";\n const mode = options?.mode;\n\n const _test = async (path: string) => {\n try {\n await access(path, mode);\n return true;\n } catch {\n return false;\n }\n };\n\n if (isAbsolute(search)) {\n return (await _test(search)) ? search : null;\n }\n\n let dir = start;\n do {\n const path = resolve(dir, search);\n const exists = await _test(path);\n\n if (exists) {\n return path;\n }\n\n dir = dir === stop ? \"\" : dirname(dir);\n } while (dir.length);\n\n return null;\n }\n}\n","import type { FSWatcher } from \"chokidar\";\nimport { watch } from \"chokidar\";\nimport { type Stats } from \"node:fs\";\nimport { resolve } from \"node:path\";\nimport type { Observable } from \"rxjs\";\nimport { Subject } from \"rxjs\";\nimport {\n ZFileSystemNodeBuilder,\n type IZFileSystemNode,\n} from \"../file-system/file-system-node.mjs\";\n\n/**\n * Represents and object that can watch a folder or file on the file system.\n */\nexport interface IZFileWatch {\n /**\n * Starts the watch operation.\n */\n start(): Promise<void>;\n\n /**\n * Stops the watch operation.\n */\n stop(): Promise<void>;\n\n /**\n * The stream for files being added.\n *\n * This can only occur if the target being watched\n * is a folder.\n *\n * @returns\n * The observable that will publish files that\n * get added.\n */\n add(): Observable<IZFileSystemNode>;\n\n /**\n * The stream for files being updated.\n *\n * If this watcher points to a folder, then all files\n * recursively will send when they get updated. If this\n * watcher points to a file, then this will only invoke\n * when the file is updated.\n *\n * @returns\n * The observable that will publish files and folders\n * that are updated.\n */\n update(): Observable<IZFileSystemNode>;\n\n /**\n * The stream for files and folders being deleted.\n *\n * If this watcher points to a folder, then all files under the\n * folder will be sent through this observable, including the\n * folder being watched. If this points to a file, then\n * this will only receive when the file is unlinked.\n *\n * @returns\n * The observable that will publish file and folders\n * that are unlinked and removed respectively. Note\n * that files and folders streamed this way will not\n * have their stats set.\n */\n remove(): Observable<IZFileSystemNode>;\n}\n\n/**\n * An implementation of the IZFileWatch.\n */\nexport class ZFileWatch implements IZFileWatch {\n private _add: Subject<IZFileSystemNode> = new Subject<IZFileSystemNode>();\n private _update: Subject<IZFileSystemNode> = new Subject<IZFileSystemNode>();\n private _remove: Subject<IZFileSystemNode> = new Subject<IZFileSystemNode>();\n private _watcher: FSWatcher | undefined;\n\n /**\n * Initializes a new instance of this object.\n *\n * @param path -\n * The path to watch.\n */\n public constructor(public readonly path: string) {}\n\n public async start() {\n await this.stop();\n\n this._watcher = watch(this.path, {\n usePolling: true,\n alwaysStat: true,\n ignoreInitial: true,\n\n awaitWriteFinish: {\n stabilityThreshold: 500,\n pollInterval: 50,\n },\n });\n\n function next(\n observable: Subject<IZFileSystemNode>,\n file: string,\n stats: Stats | undefined,\n ) {\n const node = new ZFileSystemNodeBuilder().path(resolve(this.path, file));\n observable.next(stats ? node.stats(stats).build() : node.build());\n }\n\n this._watcher\n .on(\"add\", next.bind(this, this._add))\n .on(\"addDir\", next.bind(this, this._add))\n .on(\"change\", next.bind(this, this._update))\n .on(\"unlink\", next.bind(this, this._remove))\n .on(\"unlinkDir\", next.bind(this, this._remove));\n\n return new Promise<void>((resolve) =>\n this._watcher?.on(\"ready\", () => resolve()),\n );\n }\n\n public async stop() {\n await this._watcher?.close();\n delete this._watcher;\n }\n\n public add() {\n return this._add.asObservable();\n }\n\n public update() {\n return this._update.asObservable();\n }\n\n public remove() {\n return this._remove.asObservable();\n }\n}\n","import { firstDefined, sleep } from \"@zthun/helpful-fn\";\nimport type { IZDataRequest, IZDataSource } from \"@zthun/helpful-query\";\nimport { ZDataSourceStatic } from \"@zthun/helpful-query\";\nimport { find, findIndex, flatten, trimEnd, uniqBy } from \"lodash-es\";\nimport { minimatch } from \"minimatch\";\nimport { resolve, sep } from \"node:path\";\nimport type { Subscription } from \"rxjs\";\nimport {\n ZFileSystemNodeType,\n type IZFileSystemNode,\n} from \"../file-system/file-system-node.mjs\";\nimport {\n ZFileSystemService,\n type IZFileSystemService,\n} from \"../file-system/file-system-service.mjs\";\nimport { ZFileWatch, type IZFileWatch } from \"../file-watch/file-watch.mjs\";\n\n/**\n * Represents a repository for the file system.\n */\nexport interface IZFileRepository extends IZDataSource<IZFileSystemNode> {\n /**\n * Retrieves a single file from the repository.\n *\n * @param path -\n * The fully qualified path to the file.\n *\n * @returns\n * The node that represents the file. Returns null if no\n * such file exists.\n */\n get(path: string): Promise<IZFileSystemNode | null>;\n}\n\n/**\n * Represents an implementation of a ZFileRepository that watches\n * a given path scope.\n *\n * This repository is only concerned about files. Folders\n * will not be retrieved from this repository.\n */\nexport class ZFileRepository implements IZFileRepository {\n private _service: IZFileSystemService = new ZFileSystemService();\n private _watcher: IZFileWatch | undefined;\n private _nodes: Promise<ZDataSourceStatic<IZFileSystemNode>> =\n Promise.resolve(new ZDataSourceStatic<IZFileSystemNode>([]));\n private _globs: string[] = [\"**\"];\n private _path: string = \"\";\n private _add: Subscription | undefined;\n private _remove: Subscription | undefined;\n private _update: Subscription | undefined;\n\n /**\n * Gets the path that this repository is watching.\n */\n public get path() {\n return this._path;\n }\n\n /**\n * Gets the globs matchers that this repository is matching against.\n */\n public get globs() {\n return this._globs.slice();\n }\n\n /**\n * Initializes the repository with the given root and glob filter.\n *\n * This will initially scan the file system and setup watches.\n * If you call this method again, then the repository will be\n * {@link reset} and a new set of files will be added to the\n * repository.\n *\n * @param path -\n * The root path of the repository.\n * @param globs -\n * The optional relative globs of the repository. If this is falsy,\n * then ** is used. You can achieve the same kind of operation\n * using filters, but filtering out unwanted files frees up the internal\n * memory being used.\n */\n public async initialize(path: string, globs: string[] = [\"**\"]) {\n await this.reset();\n\n this._path = path;\n this._globs = globs;\n\n // Note that this all happens in the background and should\n // only be awaited later. So the search should not be\n // required to finish when existing this method. The only\n // requirement is that the repository is reset and the path +\n // glob scope is updated. Everything beyond here should not\n // be awaited - it will be awaited later once the caller\n // tries to retrieve the files using retrieve, get, or\n // count.\n const matches = globs.map((g) =>\n this._service.search(g, {\n cwd: path,\n stat: true,\n }),\n );\n\n this._nodes = Promise.all(matches)\n .then((nodes) => {\n const flat = flatten(nodes);\n const uniq = uniqBy(flat, (n) => n.path);\n return uniq.filter((n) => n.type === ZFileSystemNodeType.File);\n })\n .then((files) => {\n return new ZDataSourceStatic(files);\n });\n\n this._watcher = new ZFileWatch(path);\n\n this._add = this._watcher\n .add()\n .subscribe(async (node: IZFileSystemNode) => {\n if (\n node.type === ZFileSystemNodeType.File &&\n this._globs.some((g) => minimatch(node.path, resolve(this._path, g)))\n ) {\n const nodes = await this._nodes;\n this._nodes = nodes.insert(node);\n }\n });\n\n this._remove = this._watcher\n .remove()\n .subscribe(async (node: IZFileSystemNode) => {\n let nodes = await this._nodes;\n const path = trimEnd(node.path, sep);\n\n // It's possible that the node given was a folder. If that happens,\n // we need to remove all files that start with the given path.\n // If the node does point to a file, then there is no possibility that\n // more than 1 item would be removed.\n\n const next = async () =>\n findIndex(await nodes.items(), (n) => {\n return (\n n.path === path ||\n (n.path.startsWith(path) &&\n n.path.substring(path.length).charAt(0) === sep)\n );\n });\n\n for (let index = await next(); index >= 0; index = await next()) {\n nodes = await nodes.removeAt(index);\n }\n\n this._nodes = Promise.resolve(nodes);\n });\n\n this._update = this._watcher\n .update()\n .subscribe(async (node: IZFileSystemNode) => {\n const nodes = await this._nodes;\n const index = findIndex(\n await nodes.items(),\n (n) => n.path === node.path,\n );\n\n // It's possible node was filtered out by the globs, or\n // it is a directory. If so, then we won't have it in our\n // list.\n if (index >= 0) {\n const next = await nodes.removeAt(index);\n this._nodes = next.insert(node, index);\n }\n });\n\n // Kick off the initial seed operation with an even loop\n // invocation.\n await sleep(100);\n\n await this._watcher?.start();\n }\n\n /**\n * Resets the repository as if it was initially created.\n */\n public async reset(): Promise<void> {\n await this._watcher?.stop();\n\n this._add?.unsubscribe();\n this._remove?.unsubscribe();\n this._update?.unsubscribe();\n\n delete this._add;\n delete this._remove;\n delete this._update;\n delete this._watcher;\n\n this._path = \"\";\n this._globs = [\"**\"];\n this._nodes = Promise.resolve(new ZDataSourceStatic<IZFileSystemNode>([]));\n }\n\n public async get(path: string): Promise<IZFileSystemNode | null> {\n const nodes = await this._nodes;\n const items = await nodes.items();\n const node = find(items, (f) => f.path === path);\n\n return firstDefined(null, node);\n }\n\n public async count(request: IZDataRequest): Promise<number> {\n const source = await this._nodes;\n return source.count(request);\n }\n\n public async retrieve(request: IZDataRequest): Promise<IZFileSystemNode[]> {\n const source = await this._nodes;\n return source.retrieve(request);\n }\n}\n","import type { PathLike } from \"node:fs\";\nimport { resolve } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\n\nexport function resolvePathLike(path: PathLike): string {\n if (typeof path === \"string\") {\n return resolve(path);\n }\n\n if (path instanceof URL) {\n return fileURLToPath(path);\n }\n\n return resolve(path.toString());\n}\n","import { sleep } from \"@zthun/helpful-fn\";\n\n/**\n * The actual delay time that you should wait for a watch\n * operation to pick up your file changes.\n */\nexport const ZWatchDelay = 1500;\n\n/**\n * Performs a sleep long enough to allow a watch operation\n * to pick up a change.\n *\n * You should never really need this. Where it is useful\n * is for unit testing with IO operations and you want to\n * wait for your write operations to get picked up by\n * a file watch operation.\n */\nexport function sleepWatchDelay() {\n return sleep(ZWatchDelay);\n}\n","import type { PathLike } from \"fs\";\nimport { mkdir } from \"fs/promises\";\nimport type { IZStreamWrite } from \"./stream-write.mjs\";\n\n/**\n * A stream that writes folders.\n *\n * Writing folders is idempotent. If the folder you\n * are trying to write already exists, then the write\n * operation still succeeds\n */\nexport class ZStreamFolder implements IZStreamWrite {\n public async write(path: PathLike): Promise<number> {\n await mkdir(path, { recursive: true });\n\n return 0;\n }\n}\n","import type { PathLike, Stats } from \"node:fs\";\nimport { readFile, stat, writeFile } from \"node:fs/promises\";\nimport { dirname } from \"path\";\nimport { resolvePathLike } from \"../resolve-path-like/resolve-path-like.js\";\nimport { ZStreamFolder } from \"./stream-folder.mjs\";\nimport type { IZStreamRead, IZStreamReadOptions } from \"./stream-read.mjs\";\nimport type { IZStreamWrite, IZStreamWriteOptions } from \"./stream-write.mjs\";\n\n/**\n * Options for the stream file object.\n */\nexport interface IZStreamFileOptions {\n /**\n * Cache options.\n *\n * A warning that file content caching will take up significant memory\n * if the file size is too big or the max files is too big. Make sure\n * you know what you're doing when you change the default values of this.\n */\n cache?: {\n /**\n * Maximum number of bytes a file can be before it will not be cached.\n * The default is 100 Kib (102400 bytes)\n *\n * @default 102400\n */\n fileSize?: bigint;\n /**\n * The maximum number of files that are to be cached. The cache order\n * is first in, first out. Set this to 0 to not cache anything. The\n * default is 1000.\n *\n * @default 1000\n */\n maxFiles?: number;\n };\n}\n\n/**\n * A stream that can read and write to files.\n *\n * This is mostly a wrapper to readFile and writeFile from node, but\n * with some optimizations.\n *\n * First, this class supports file content caching so reading in a file\n * that's under a certain size threshold will store it in memory for\n * later retrieval.\n */\nexport class ZStreamFile implements IZStreamWrite, IZStreamRead {\n private static readonly FileSizeDefault = 102400; // One Hundred KibiBytes\n private static readonly MaxFilesDefault = 1000;\n\n private _cache = new Map<string, { stats: Stats; buffer: Promise<Buffer> }>();\n\n /**\n * Initializes a new instance of this object.\n *\n * @param options -\n * The options for file read and writes.\n */\n public constructor(public readonly options: IZStreamFileOptions = {}) {}\n\n public async read(\n path: PathLike,\n options?: IZStreamReadOptions,\n ): Promise<Buffer> {\n const _path = resolvePathLike(path);\n\n const stats = await stat(_path);\n const cached = this._cache.get(_path);\n\n const buffer =\n cached && cached.stats.mtimeMs >= stats.mtimeMs\n ? cached.buffer\n : readFile(_path, options);\n\n return this._addToCache(_path, { stats, buffer });\n }\n\n public async write(\n path: PathLike,\n { buffer = Buffer.from(\"\") }: IZStreamWriteOptions = {},\n ): Promise<number> {\n const _path = resolvePathLike(path);\n const directory = dirname(_path);\n\n await new ZStreamFolder().write(directory);\n await writeFile(_path, buffer, { flush: true });\n\n // If this file specifically was cached earlier,\n // we can just remove it now so we make room for\n // another file. Consumers can just read the\n // file again to recache it.\n this._cache.delete(_path);\n\n return buffer.length;\n }\n\n private _addToCache(\n path: string,\n item: { stats: Stats; buffer: Promise<Buffer> },\n ) {\n const { cache = {} } = this.options;\n const {\n fileSize = ZStreamFile.FileSizeDefault,\n maxFiles = ZStreamFile.MaxFilesDefault,\n } = cache;\n\n if (item.stats.size > fileSize) {\n // In this case, the file size is too big to cache in memory,\n // so we're bowing out here.\n return item.buffer;\n }\n\n // We will remove this path from the cache first since\n // we want it to be the most recent file (at the end)\n // of the key list. The removal does nothing if the\n // file was not cached.\n this._cache.delete(path);\n this._cache.set(path, item);\n\n if (this._cache.size > maxFiles) {\n // Retrieving the keys from a javascript map is order\n // by the time in which the keys are created. So\n // we are going to remove the first key which is the\n // oldest.\n const itr = this._cache.keys();\n this._cache.delete(itr.next().value);\n }\n\n return item.buffer;\n }\n}\n"],"names":["ZFileSystemNodeType","ZFileSystemNodeBuilder","created","at","_node","Date","toJSON","updated","size","bytes","BigInt","path","decorate","type","stats","s","builder","birthtime","mtime","isFile","file","folder","build","clone","structuredClone","omitBy","isUndefined","name","basename","extension","title","parent","dirname","extname","_define_property","bind","ZFileSystemService","info","search","pattern","options","paths","glob","stat","withFileTypes","map","fullpath","atime","undefined","walk","start","cwd","stop","mode","_test","access","isAbsolute","dir","resolve","exists","length","ZFileWatch","_watcher","watch","usePolling","alwaysStat","ignoreInitial","awaitWriteFinish","stabilityThreshold","pollInterval","next","observable","node","on","_add","_update","_remove","Promise","close","add","asObservable","update","remove","Subject","ZFileRepository","_path","globs","_globs","slice","initialize","reset","matches","g","_service","_nodes","all","then","nodes","flat","flatten","uniq","uniqBy","n","filter","File","files","ZDataSourceStatic","subscribe","some","minimatch","insert","trimEnd","sep","findIndex","items","startsWith","substring","charAt","index","removeAt","sleep","unsubscribe","get","find","f","firstDefined","count","request","source","retrieve","resolvePathLike","URL","fileURLToPath","toString","ZWatchDelay","sleepWatchDelay","ZStreamFolder","write","mkdir","recursive","ZStreamFile","read","cached","_cache","buffer","mtimeMs","readFile","_addToCache","Buffer","from","directory","writeFile","flush","delete","item","cache","fileSize","FileSizeDefault","maxFiles","MaxFilesDefault","set","itr","keys","value","Map"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;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,CAAC9I,IAAAA,CAAAA;AACnB,QAAA,IAAI,CAACoI,MAAM,CAACiB,GAAG,CAACrJ,IAAAA,EAAM+I,IAAAA,CAAAA;AAEtB,QAAA,IAAI,IAAI,CAACX,MAAM,CAACvI,IAAI,GAAGsJ,QAAAA,EAAU;;;;;AAK/B,YAAA,MAAMG,GAAAA,GAAM,IAAI,CAAClB,MAAM,CAACmB,IAAI,EAAA;YAC5B,IAAI,CAACnB,MAAM,CAACU,MAAM,CAACQ,GAAAA,CAAI3F,IAAI,GAAG6F,KAAK,CAAA;AACrC,QAAA;AAEA,QAAA,OAAOT,KAAKV,MAAM;AACpB,IAAA;AA7EA;;;;;AAKC,MACD,WAAA,CAAmCxG,OAAAA,GAA+B,EAAE,CAAE;;AARtE,QAAA,gBAAA,CAAA,IAAA,EAAQuG,UAAR,MAAA,CAAA;aAQmCvG,OAAAA,GAAAA,OAAAA;AAR3BuG,QAAAA,IAAAA,CAAAA,MAAAA,GAAS,IAAIqB,GAAAA,EAAAA;AAQkD,IAAA;AAwEzE;AAnFE,gBAAA,CADWxB,WAAAA,EACaiB,iBAAAA,EAAkB,MAAA,CAAA,CAAA;AAC1C,gBAAA,CAFWjB,aAEamB,iBAAAA,EAAkB,IAAA,CAAA;;;;;;;;;;;;;"}
package/dist/index.js CHANGED
@@ -179,7 +179,6 @@ function _define_property$2(obj, key, value) {
179
179
  async stop() {
180
180
  await this._watcher?.close();
181
181
  delete this._watcher;
182
- return Promise.resolve();
183
182
  }
184
183
  add() {
185
184
  return this._add.asObservable();
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/file-system/file-system-node.mts","../src/file-system/file-system-service.mts","../src/file-watch/file-watch.mts","../src/file-repository/file-repository.mts","../src/resolve-path-like/resolve-path-like.ts","../src/sleep-watch-delay/sleep-watch-delay.mts","../src/stream/stream-folder.mts","../src/stream/stream-file.mts"],"sourcesContent":["import { type ZMutable } from \"@zthun/helpful-fn\";\nimport { isUndefined, omitBy } from \"lodash-es\";\nimport type { Stats } from \"node:fs\";\nimport { basename, dirname, extname } from \"node:path\";\n\n/**\n * Represents a type of a file system node.\n */\nexport enum ZFileSystemNodeType {\n File = \"file\",\n Folder = \"folder\",\n}\n\nexport interface IZFileSystemNode {\n /**\n * The absolute path of the node.\n */\n path: string;\n\n /**\n * The type of the node (file or folder).\n */\n type: ZFileSystemNodeType;\n\n /**\n * The creation date of the node.\n */\n created?: string;\n\n /**\n * The modification date of the node.\n */\n updated?: string;\n\n /**\n * The size of the node in bytes.\n */\n size?: bigint;\n\n /**\n * The file or folder name with the extension.\n *\n * Calculated from the path.\n */\n readonly name: string;\n\n /**\n * The file extension.\n *\n * Calculated from the path.\n */\n readonly extension: string;\n\n /**\n * File title.\n *\n * The name without the extension.\n * Calculated from the path.\n */\n readonly title: string;\n\n /**\n * Parent directory path.\n */\n readonly parent: string;\n}\n\n/**\n * Represents a builder for a file system node.\n */\nexport class ZFileSystemNodeBuilder {\n private _node: ZMutable<IZFileSystemNode> = {\n path: \"/\",\n type: ZFileSystemNodeType.Folder,\n extension: \"\",\n name: \"\",\n parent: \"\",\n title: \"\",\n };\n\n public created(at?: Date | string | undefined) {\n this._node.created = at instanceof Date ? at.toJSON() : at;\n\n return this;\n }\n\n public updated(at?: Date | string | undefined) {\n this._node.updated = at instanceof Date ? at.toJSON() : at;\n\n return this;\n }\n\n public size(bytes: bigint | number | undefined) {\n this._node.size = typeof bytes == \"number\" ? BigInt(bytes) : bytes;\n\n return this;\n }\n\n public path(path: string) {\n this._node.path = path;\n\n return this.decorate();\n }\n\n public type(type: ZFileSystemNodeType) {\n this._node.type = type;\n\n return this.decorate();\n }\n\n public file = this.type.bind(this, ZFileSystemNodeType.File);\n public folder = this.type.bind(this, ZFileSystemNodeType.Folder);\n\n public stats(s: Stats) {\n const builder = this.size(s.size).created(s.birthtime).updated(s.mtime);\n\n return s.isFile() ? builder.file() : builder.folder();\n }\n\n public build() {\n const clone = structuredClone(this._node);\n\n return omitBy(clone, isUndefined) as IZFileSystemNode;\n }\n\n private decorate() {\n const { path, type } = this._node;\n\n this._node.name = basename(path);\n this._node.extension = \"\";\n this._node.title = this._node.name;\n this._node.parent = dirname(path);\n\n if (type === ZFileSystemNodeType.File) {\n const extension = extname(path);\n this._node.extension = extension;\n this._node.title = basename(path, extension);\n }\n\n if (!path || path === \"/\" || this._node.parent === \".\") {\n this._node.parent = \"\";\n }\n\n return this;\n }\n}\n","import { glob } from \"glob\";\nimport { access } from \"node:fs/promises\";\nimport { dirname, isAbsolute, resolve } from \"node:path\";\nimport { cwd } from \"node:process\";\nimport type { IZFileSystemNode } from \"./file-system-node.mjs\";\nimport { ZFileSystemNodeBuilder } from \"./file-system-node.mjs\";\n\n/**\n * Represents options for searches.\n */\nexport interface IZFileSystemSearchOptions {\n /**\n * The directory to search in.\n *\n * If this is not set, then the cwd of the application is used.\n */\n cwd?: string;\n\n /**\n * A flag that determines whether or not to load the\n * file system information.\n *\n * This is true by default.\n */\n stat?: boolean;\n}\n\n/**\n * Represents options for directory walking.\n */\nexport interface IZFileSystemWalkOptions {\n /**\n * The starting directory.\n *\n * The default is the current working directory\n *\n * @see process.cwd for more information.\n */\n start?: string;\n\n /**\n * The directory to stop at.\n *\n * The default is the root of the file system.\n */\n stop?: string;\n\n /**\n * The type of mode that the path must support in order\n * to be approved.\n *\n * The default is undefined and left up to the node api.\n */\n mode?: number;\n}\n\n/**\n * Represents a service to enumerate the file system.\n */\nexport interface IZFileSystemService {\n /**\n * Gets information about a node.\n *\n * @param path -\n * The path to get information for.\n *\n * @returns\n * Information about the node.\n */\n info(path: string): Promise<IZFileSystemNode>;\n\n /**\n * Reads all nodes that match a pattern.\n *\n * @param pattern -\n * The pattern string to match against or a list\n * of patterns to match.\n * @param options -\n * The options for the search.\n *\n * @returns\n * A list of path strings that match the given patterns.\n */\n search(\n pattern: string | string[],\n options?: IZFileSystemSearchOptions,\n ): Promise<IZFileSystemNode[]>;\n\n /**\n * Walks up a directory tree to search for existence of a given path.\n *\n * @param search -\n * The path to search for. This is the candidate folder path that\n * may or may not exist somewhere from the start directory all the\n * way up the directory tree.\n * @param options -\n * The given options for the search.\n *\n * @returns\n * The fully qualified path to the first path that matches the search\n * starting at the options start or the current working directory if not\n * specified. Returns null if no such directory exists.\n *\n * @example\n *\n * ```ts\n * import { resolve } from 'path'\n *\n * // Find any folder named .vscode from the current working directory all the way\n * // up the directory tree. Returns null if no vscode directory can be found.\n * const service = new ZFileSystemService();\n * const vscode = service.walk('.vscode');\n *\n * // Walk the directory tree from the current script and find the .config folder.\n * const config = service.walk('.config', { start: __dirname });\n *\n * // Walk the directory tree from the current script and stop when we reach\n * // at most 2 directories up.\n * const start = __dirname;\n * const stop = resolve(__dirname, '../..');\n * const file = service.walk('path/to/file.json', { start, stop });\n * ```\n */\n walk(\n search: string,\n options?: IZFileSystemWalkOptions,\n ): Promise<string | null>;\n}\n\n/**\n * Represents a node implementation of a file system service.\n */\nexport class ZFileSystemService implements IZFileSystemService {\n public async info(path: string): Promise<IZFileSystemNode> {\n const [file] = await this.search(path);\n return file;\n }\n\n public async search(\n pattern: string | string[],\n options?: IZFileSystemSearchOptions,\n ): Promise<IZFileSystemNode[]> {\n const paths = await glob(pattern, {\n stat: true,\n ...options,\n withFileTypes: true,\n });\n\n return paths.map((path) => {\n let info = new ZFileSystemNodeBuilder()\n .path(path.fullpath())\n .created(path.birthtime)\n .updated(path.atime)\n .size(path.size);\n\n // Note that for folders, node will return the size of the underlying OS metadata,\n // hence, why we remove the size on the folder here.\n info = path.isFile() ? info.file() : info.folder().size(undefined);\n\n return info.build();\n });\n }\n\n public async walk(search: string, options?: IZFileSystemWalkOptions) {\n const start = options?.start || cwd();\n const stop = options?.stop || \"/\";\n const mode = options?.mode;\n\n const _test = async (path: string) => {\n try {\n await access(path, mode);\n return true;\n } catch {\n return false;\n }\n };\n\n if (isAbsolute(search)) {\n return (await _test(search)) ? search : null;\n }\n\n let dir = start;\n do {\n const path = resolve(dir, search);\n const exists = await _test(path);\n\n if (exists) {\n return path;\n }\n\n dir = dir === stop ? \"\" : dirname(dir);\n } while (dir.length);\n\n return null;\n }\n}\n","import type { FSWatcher } from \"chokidar\";\nimport { watch } from \"chokidar\";\nimport type { Stats } from \"node:fs\";\nimport { resolve } from \"node:path\";\nimport type { Observable } from \"rxjs\";\nimport { Subject } from \"rxjs\";\nimport {\n ZFileSystemNodeBuilder,\n type IZFileSystemNode,\n} from \"../file-system/file-system-node.mjs\";\n\n/**\n * Represents and object that can watch a folder or file on the file system.\n */\nexport interface IZFileWatch {\n /**\n * Starts the watch operation.\n */\n start(): Promise<void>;\n\n /**\n * Stops the watch operation.\n */\n stop(): Promise<void>;\n\n /**\n * The stream for files being added.\n *\n * This can only occur if the target being watched\n * is a folder.\n *\n * @returns\n * The observable that will publish files that\n * get added.\n */\n add(): Observable<IZFileSystemNode>;\n\n /**\n * The stream for files being updated.\n *\n * If this watcher points to a folder, then all files\n * recursively will send when they get updated. If this\n * watcher points to a file, then this will only invoke\n * when the file is updated.\n *\n * @returns\n * The observable that will publish files and folders\n * that are updated.\n */\n update(): Observable<IZFileSystemNode>;\n\n /**\n * The stream for files and folders being deleted.\n *\n * If this watcher points to a folder, then all files under the\n * folder will be sent through this observable, including the\n * folder being watched. If this points to a file, then\n * this will only receive when the file is unlinked.\n *\n * @returns\n * The observable that will publish file and folders\n * that are unlinked and removed respectively. Note\n * that files and folders streamed this way will not\n * have their stats set.\n */\n remove(): Observable<IZFileSystemNode>;\n}\n\n/**\n * An implementation of the IZFileWatch.\n */\nexport class ZFileWatch implements IZFileWatch {\n private _add: Subject<IZFileSystemNode> = new Subject<IZFileSystemNode>();\n private _update: Subject<IZFileSystemNode> = new Subject<IZFileSystemNode>();\n private _remove: Subject<IZFileSystemNode> = new Subject<IZFileSystemNode>();\n private _watcher: FSWatcher | undefined;\n\n /**\n * Initializes a new instance of this object.\n *\n * @param path -\n * The path to watch.\n */\n public constructor(public readonly path: string) {}\n\n public async start() {\n await this.stop();\n\n this._watcher = watch(this.path, {\n usePolling: true,\n alwaysStat: true,\n ignoreInitial: true,\n\n awaitWriteFinish: {\n stabilityThreshold: 500,\n pollInterval: 50,\n },\n });\n\n function next(\n observable: Subject<IZFileSystemNode>,\n file: string,\n stats: Stats | undefined,\n ) {\n const node = new ZFileSystemNodeBuilder().path(resolve(this.path, file));\n observable.next(stats ? node.stats(stats).build() : node.build());\n }\n\n this._watcher\n .on(\"add\", next.bind(this, this._add))\n .on(\"addDir\", next.bind(this, this._add))\n .on(\"change\", next.bind(this, this._update))\n .on(\"unlink\", next.bind(this, this._remove))\n .on(\"unlinkDir\", next.bind(this, this._remove));\n\n return new Promise<void>((resolve) =>\n this._watcher?.on(\"ready\", () => resolve()),\n );\n }\n\n public async stop() {\n await this._watcher?.close();\n delete this._watcher;\n return Promise.resolve();\n }\n\n public add() {\n return this._add.asObservable();\n }\n\n public update() {\n return this._update.asObservable();\n }\n\n public remove() {\n return this._remove.asObservable();\n }\n}\n","import { firstDefined, sleep } from \"@zthun/helpful-fn\";\nimport type { IZDataRequest, IZDataSource } from \"@zthun/helpful-query\";\nimport { ZDataSourceStatic } from \"@zthun/helpful-query\";\nimport { find, findIndex, flatten, trimEnd, uniqBy } from \"lodash-es\";\nimport { minimatch } from \"minimatch\";\nimport { resolve, sep } from \"node:path\";\nimport type { Subscription } from \"rxjs\";\nimport {\n ZFileSystemNodeType,\n type IZFileSystemNode,\n} from \"../file-system/file-system-node.mjs\";\nimport {\n ZFileSystemService,\n type IZFileSystemService,\n} from \"../file-system/file-system-service.mjs\";\nimport { ZFileWatch, type IZFileWatch } from \"../file-watch/file-watch.mjs\";\n\n/**\n * Represents a repository for the file system.\n */\nexport interface IZFileRepository extends IZDataSource<IZFileSystemNode> {\n /**\n * Retrieves a single file from the repository.\n *\n * @param path -\n * The fully qualified path to the file.\n *\n * @returns\n * The node that represents the file. Returns null if no\n * such file exists.\n */\n get(path: string): Promise<IZFileSystemNode | null>;\n}\n\n/**\n * Represents an implementation of a ZFileRepository that watches\n * a given path scope.\n *\n * This repository is only concerned about files. Folders\n * will not be retrieved from this repository.\n */\nexport class ZFileRepository implements IZFileRepository {\n private _service: IZFileSystemService = new ZFileSystemService();\n private _watcher: IZFileWatch | undefined;\n private _nodes: Promise<ZDataSourceStatic<IZFileSystemNode>> =\n Promise.resolve(new ZDataSourceStatic<IZFileSystemNode>([]));\n private _globs: string[] = [\"**\"];\n private _path: string = \"\";\n private _add: Subscription | undefined;\n private _remove: Subscription | undefined;\n private _update: Subscription | undefined;\n\n /**\n * Gets the path that this repository is watching.\n */\n public get path() {\n return this._path;\n }\n\n /**\n * Gets the globs matchers that this repository is matching against.\n */\n public get globs() {\n return this._globs.slice();\n }\n\n /**\n * Initializes the repository with the given root and glob filter.\n *\n * This will initially scan the file system and setup watches.\n * If you call this method again, then the repository will be\n * {@link reset} and a new set of files will be added to the\n * repository.\n *\n * @param path -\n * The root path of the repository.\n * @param globs -\n * The optional relative globs of the repository. If this is falsy,\n * then ** is used. You can achieve the same kind of operation\n * using filters, but filtering out unwanted files frees up the internal\n * memory being used.\n */\n public async initialize(path: string, globs: string[] = [\"**\"]) {\n await this.reset();\n\n this._path = path;\n this._globs = globs;\n\n // Note that this all happens in the background and should\n // only be awaited later. So the search should not be\n // required to finish when existing this method. The only\n // requirement is that the repository is reset and the path +\n // glob scope is updated. Everything beyond here should not\n // be awaited - it will be awaited later once the caller\n // tries to retrieve the files using retrieve, get, or\n // count.\n const matches = globs.map((g) =>\n this._service.search(g, {\n cwd: path,\n stat: true,\n }),\n );\n\n this._nodes = Promise.all(matches)\n .then((nodes) => {\n const flat = flatten(nodes);\n const uniq = uniqBy(flat, (n) => n.path);\n return uniq.filter((n) => n.type === ZFileSystemNodeType.File);\n })\n .then((files) => {\n return new ZDataSourceStatic(files);\n });\n\n this._watcher = new ZFileWatch(path);\n\n this._add = this._watcher\n .add()\n .subscribe(async (node: IZFileSystemNode) => {\n if (\n node.type === ZFileSystemNodeType.File &&\n this._globs.some((g) => minimatch(node.path, resolve(this._path, g)))\n ) {\n const nodes = await this._nodes;\n this._nodes = nodes.insert(node);\n }\n });\n\n this._remove = this._watcher\n .remove()\n .subscribe(async (node: IZFileSystemNode) => {\n let nodes = await this._nodes;\n const path = trimEnd(node.path, sep);\n\n // It's possible that the node given was a folder. If that happens,\n // we need to remove all files that start with the given path.\n // If the node does point to a file, then there is no possibility that\n // more than 1 item would be removed.\n\n const next = async () =>\n findIndex(await nodes.items(), (n) => {\n return (\n n.path === path ||\n (n.path.startsWith(path) &&\n n.path.substring(path.length).charAt(0) === sep)\n );\n });\n\n for (let index = await next(); index >= 0; index = await next()) {\n nodes = await nodes.removeAt(index);\n }\n\n this._nodes = Promise.resolve(nodes);\n });\n\n this._update = this._watcher\n .update()\n .subscribe(async (node: IZFileSystemNode) => {\n const nodes = await this._nodes;\n const index = findIndex(\n await nodes.items(),\n (n) => n.path === node.path,\n );\n\n // It's possible node was filtered out by the globs, or\n // it is a directory. If so, then we won't have it in our\n // list.\n if (index >= 0) {\n const next = await nodes.removeAt(index);\n this._nodes = next.insert(node, index);\n }\n });\n\n // Kick off the initial seed operation with an even loop\n // invocation.\n await sleep(100);\n\n await this._watcher?.start();\n }\n\n /**\n * Resets the repository as if it was initially created.\n */\n public async reset(): Promise<void> {\n await this._watcher?.stop();\n\n this._add?.unsubscribe();\n this._remove?.unsubscribe();\n this._update?.unsubscribe();\n\n delete this._add;\n delete this._remove;\n delete this._update;\n delete this._watcher;\n\n this._path = \"\";\n this._globs = [\"**\"];\n this._nodes = Promise.resolve(new ZDataSourceStatic<IZFileSystemNode>([]));\n }\n\n public async get(path: string): Promise<IZFileSystemNode | null> {\n const nodes = await this._nodes;\n const items = await nodes.items();\n const node = find(items, (f) => f.path === path);\n\n return firstDefined(null, node);\n }\n\n public async count(request: IZDataRequest): Promise<number> {\n const source = await this._nodes;\n return source.count(request);\n }\n\n public async retrieve(request: IZDataRequest): Promise<IZFileSystemNode[]> {\n const source = await this._nodes;\n return source.retrieve(request);\n }\n}\n","import type { PathLike } from \"node:fs\";\nimport { resolve } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\n\nexport function resolvePathLike(path: PathLike): string {\n if (typeof path === \"string\") {\n return resolve(path);\n }\n\n if (path instanceof URL) {\n return fileURLToPath(path);\n }\n\n return resolve(path.toString());\n}\n","import { sleep } from \"@zthun/helpful-fn\";\n\n/**\n * The actual delay time that you should wait for a watch\n * operation to pick up your file changes.\n */\nexport const ZWatchDelay = 1500;\n\n/**\n * Performs a sleep long enough to allow a watch operation\n * to pick up a change.\n *\n * You should never really need this. Where it is useful\n * is for unit testing with IO operations and you want to\n * wait for your write operations to get picked up by\n * a file watch operation.\n */\nexport function sleepWatchDelay() {\n return sleep(ZWatchDelay);\n}\n","import type { PathLike } from \"fs\";\nimport { mkdir } from \"fs/promises\";\nimport type { IZStreamWrite } from \"./stream-write.mjs\";\n\n/**\n * A stream that writes folders.\n *\n * Writing folders is idempotent. If the folder you\n * are trying to write already exists, then the write\n * operation still succeeds\n */\nexport class ZStreamFolder implements IZStreamWrite {\n public async write(path: PathLike): Promise<number> {\n await mkdir(path, { recursive: true });\n\n return 0;\n }\n}\n","import type { PathLike, Stats } from \"node:fs\";\nimport { readFile, stat, writeFile } from \"node:fs/promises\";\nimport { dirname } from \"path\";\nimport { resolvePathLike } from \"../resolve-path-like/resolve-path-like.js\";\nimport { ZStreamFolder } from \"./stream-folder.mjs\";\nimport type { IZStreamRead, IZStreamReadOptions } from \"./stream-read.mjs\";\nimport type { IZStreamWrite, IZStreamWriteOptions } from \"./stream-write.mjs\";\n\n/**\n * Options for the stream file object.\n */\nexport interface IZStreamFileOptions {\n /**\n * Cache options.\n *\n * A warning that file content caching will take up significant memory\n * if the file size is too big or the max files is too big. Make sure\n * you know what you're doing when you change the default values of this.\n */\n cache?: {\n /**\n * Maximum number of bytes a file can be before it will not be cached.\n * The default is 100 Kib (102400 bytes)\n *\n * @default 102400\n */\n fileSize?: bigint;\n /**\n * The maximum number of files that are to be cached. The cache order\n * is first in, first out. Set this to 0 to not cache anything. The\n * default is 1000.\n *\n * @default 1000\n */\n maxFiles?: number;\n };\n}\n\n/**\n * A stream that can read and write to files.\n *\n * This is mostly a wrapper to readFile and writeFile from node, but\n * with some optimizations.\n *\n * First, this class supports file content caching so reading in a file\n * that's under a certain size threshold will store it in memory for\n * later retrieval.\n */\nexport class ZStreamFile implements IZStreamWrite, IZStreamRead {\n private static readonly FileSizeDefault = 102400; // One Hundred KibiBytes\n private static readonly MaxFilesDefault = 1000;\n\n private _cache = new Map<string, { stats: Stats; buffer: Promise<Buffer> }>();\n\n /**\n * Initializes a new instance of this object.\n *\n * @param options -\n * The options for file read and writes.\n */\n public constructor(public readonly options: IZStreamFileOptions = {}) {}\n\n public async read(\n path: PathLike,\n options?: IZStreamReadOptions,\n ): Promise<Buffer> {\n const _path = resolvePathLike(path);\n\n const stats = await stat(_path);\n const cached = this._cache.get(_path);\n\n const buffer =\n cached && cached.stats.mtimeMs >= stats.mtimeMs\n ? cached.buffer\n : readFile(_path, options);\n\n return this._addToCache(_path, { stats, buffer });\n }\n\n public async write(\n path: PathLike,\n { buffer = Buffer.from(\"\") }: IZStreamWriteOptions = {},\n ): Promise<number> {\n const _path = resolvePathLike(path);\n const directory = dirname(_path);\n\n await new ZStreamFolder().write(directory);\n await writeFile(_path, buffer, { flush: true });\n\n // If this file specifically was cached earlier,\n // we can just remove it now so we make room for\n // another file. Consumers can just read the\n // file again to recache it.\n this._cache.delete(_path);\n\n return buffer.length;\n }\n\n private _addToCache(\n path: string,\n item: { stats: Stats; buffer: Promise<Buffer> },\n ) {\n const { cache = {} } = this.options;\n const {\n fileSize = ZStreamFile.FileSizeDefault,\n maxFiles = ZStreamFile.MaxFilesDefault,\n } = cache;\n\n if (item.stats.size > fileSize) {\n // In this case, the file size is too big to cache in memory,\n // so we're bowing out here.\n return item.buffer;\n }\n\n // We will remove this path from the cache first since\n // we want it to be the most recent file (at the end)\n // of the key list. The removal does nothing if the\n // file was not cached.\n this._cache.delete(path);\n this._cache.set(path, item);\n\n if (this._cache.size > maxFiles) {\n // Retrieving the keys from a javascript map is order\n // by the time in which the keys are created. So\n // we are going to remove the first key which is the\n // oldest.\n const itr = this._cache.keys();\n this._cache.delete(itr.next().value);\n }\n\n return item.buffer;\n }\n}\n"],"names":["ZFileSystemNodeType","ZFileSystemNodeBuilder","created","at","_node","Date","toJSON","updated","size","bytes","BigInt","path","decorate","type","stats","s","builder","birthtime","mtime","isFile","file","folder","build","clone","structuredClone","omitBy","isUndefined","name","basename","extension","title","parent","dirname","extname","_define_property","bind","ZFileSystemService","info","search","pattern","options","paths","glob","stat","withFileTypes","map","fullpath","atime","undefined","walk","start","cwd","stop","mode","_test","access","isAbsolute","dir","resolve","exists","length","ZFileWatch","_watcher","watch","usePolling","alwaysStat","ignoreInitial","awaitWriteFinish","stabilityThreshold","pollInterval","next","observable","node","on","_add","_update","_remove","Promise","close","add","asObservable","update","remove","Subject","ZFileRepository","_path","globs","_globs","slice","initialize","reset","matches","g","_service","_nodes","all","then","nodes","flat","flatten","uniq","uniqBy","n","filter","File","files","ZDataSourceStatic","subscribe","some","minimatch","insert","trimEnd","sep","findIndex","items","startsWith","substring","charAt","index","removeAt","sleep","unsubscribe","get","find","f","firstDefined","count","request","source","retrieve","resolvePathLike","URL","fileURLToPath","toString","ZWatchDelay","sleepWatchDelay","ZStreamFolder","write","mkdir","recursive","ZStreamFile","read","cached","_cache","buffer","mtimeMs","readFile","_addToCache","Buffer","from","directory","writeFile","flush","delete","item","cache","fileSize","FileSizeDefault","maxFiles","MaxFilesDefault","set","itr","keys","value","Map"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAKA;;IAGO,IAAKA,mBAAAA,iBAAAA,SAAAA,mBAAAA,EAAAA;;;AAAAA,IAAAA,OAAAA,mBAAAA;AAGX,CAAA,CAAA,EAAA;AAwDD;;AAEC,IACM,MAAMC,sBAAAA,CAAAA;AAUJC,IAAAA,OAAAA,CAAQC,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AAK/B,YAAA,MAAMG,GAAAA,GAAM,IAAI,CAAClB,MAAM,CAACmB,IAAI,EAAA;YAC5B,IAAI,CAACnB,MAAM,CAACU,MAAM,CAACQ,GAAAA,CAAI3F,IAAI,GAAG6F,KAAK,CAAA;AACrC,QAAA;AAEA,QAAA,OAAOT,KAAKV,MAAM;AACpB,IAAA;AA7EA;;;;;AAKC,MACD,WAAA,CAAmCxG,OAAAA,GAA+B,EAAE,CAAE;;AARtE,QAAA,gBAAA,CAAA,IAAA,EAAQuG,UAAR,MAAA,CAAA;aAQmCvG,OAAAA,GAAAA,OAAAA;AAR3BuG,QAAAA,IAAAA,CAAAA,MAAAA,GAAS,IAAIqB,GAAAA,EAAAA;AAQkD,IAAA;AAwEzE;AAnFE,gBAAA,CADWxB,WAAAA,EACaiB,iBAAAA,EAAkB,MAAA,CAAA,CAAA;AAC1C,gBAAA,CAFWjB,aAEamB,iBAAAA,EAAkB,IAAA,CAAA;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../src/file-system/file-system-node.mts","../src/file-system/file-system-service.mts","../src/file-watch/file-watch.mts","../src/file-repository/file-repository.mts","../src/resolve-path-like/resolve-path-like.ts","../src/sleep-watch-delay/sleep-watch-delay.mts","../src/stream/stream-folder.mts","../src/stream/stream-file.mts"],"sourcesContent":["import { type ZMutable } from \"@zthun/helpful-fn\";\nimport { isUndefined, omitBy } from \"lodash-es\";\nimport type { Stats } from \"node:fs\";\nimport { basename, dirname, extname } from \"node:path\";\n\n/**\n * Represents a type of a file system node.\n */\nexport enum ZFileSystemNodeType {\n File = \"file\",\n Folder = \"folder\",\n}\n\nexport interface IZFileSystemNode {\n /**\n * The absolute path of the node.\n */\n path: string;\n\n /**\n * The type of the node (file or folder).\n */\n type: ZFileSystemNodeType;\n\n /**\n * The creation date of the node.\n */\n created?: string;\n\n /**\n * The modification date of the node.\n */\n updated?: string;\n\n /**\n * The size of the node in bytes.\n */\n size?: bigint;\n\n /**\n * The file or folder name with the extension.\n *\n * Calculated from the path.\n */\n readonly name: string;\n\n /**\n * The file extension.\n *\n * Calculated from the path.\n */\n readonly extension: string;\n\n /**\n * File title.\n *\n * The name without the extension.\n * Calculated from the path.\n */\n readonly title: string;\n\n /**\n * Parent directory path.\n */\n readonly parent: string;\n}\n\n/**\n * Represents a builder for a file system node.\n */\nexport class ZFileSystemNodeBuilder {\n private _node: ZMutable<IZFileSystemNode> = {\n path: \"/\",\n type: ZFileSystemNodeType.Folder,\n extension: \"\",\n name: \"\",\n parent: \"\",\n title: \"\",\n };\n\n public created(at?: Date | string | undefined) {\n this._node.created = at instanceof Date ? at.toJSON() : at;\n\n return this;\n }\n\n public updated(at?: Date | string | undefined) {\n this._node.updated = at instanceof Date ? at.toJSON() : at;\n\n return this;\n }\n\n public size(bytes: bigint | number | undefined) {\n this._node.size = typeof bytes == \"number\" ? BigInt(bytes) : bytes;\n\n return this;\n }\n\n public path(path: string) {\n this._node.path = path;\n\n return this.decorate();\n }\n\n public type(type: ZFileSystemNodeType) {\n this._node.type = type;\n\n return this.decorate();\n }\n\n public file = this.type.bind(this, ZFileSystemNodeType.File);\n public folder = this.type.bind(this, ZFileSystemNodeType.Folder);\n\n public stats(s: Stats) {\n const builder = this.size(s.size).created(s.birthtime).updated(s.mtime);\n\n return s.isFile() ? builder.file() : builder.folder();\n }\n\n public build() {\n const clone = structuredClone(this._node);\n\n return omitBy(clone, isUndefined) as IZFileSystemNode;\n }\n\n private decorate() {\n const { path, type } = this._node;\n\n this._node.name = basename(path);\n this._node.extension = \"\";\n this._node.title = this._node.name;\n this._node.parent = dirname(path);\n\n if (type === ZFileSystemNodeType.File) {\n const extension = extname(path);\n this._node.extension = extension;\n this._node.title = basename(path, extension);\n }\n\n if (!path || path === \"/\" || this._node.parent === \".\") {\n this._node.parent = \"\";\n }\n\n return this;\n }\n}\n","import { glob } from \"glob\";\nimport { access } from \"node:fs/promises\";\nimport { dirname, isAbsolute, resolve } from \"node:path\";\nimport { cwd } from \"node:process\";\nimport type { IZFileSystemNode } from \"./file-system-node.mjs\";\nimport { ZFileSystemNodeBuilder } from \"./file-system-node.mjs\";\n\n/**\n * Represents options for searches.\n */\nexport interface IZFileSystemSearchOptions {\n /**\n * The directory to search in.\n *\n * If this is not set, then the cwd of the application is used.\n */\n cwd?: string;\n\n /**\n * A flag that determines whether or not to load the\n * file system information.\n *\n * This is true by default.\n */\n stat?: boolean;\n}\n\n/**\n * Represents options for directory walking.\n */\nexport interface IZFileSystemWalkOptions {\n /**\n * The starting directory.\n *\n * The default is the current working directory\n *\n * @see process.cwd for more information.\n */\n start?: string;\n\n /**\n * The directory to stop at.\n *\n * The default is the root of the file system.\n */\n stop?: string;\n\n /**\n * The type of mode that the path must support in order\n * to be approved.\n *\n * The default is undefined and left up to the node api.\n */\n mode?: number;\n}\n\n/**\n * Represents a service to enumerate the file system.\n */\nexport interface IZFileSystemService {\n /**\n * Gets information about a node.\n *\n * @param path -\n * The path to get information for.\n *\n * @returns\n * Information about the node.\n */\n info(path: string): Promise<IZFileSystemNode>;\n\n /**\n * Reads all nodes that match a pattern.\n *\n * @param pattern -\n * The pattern string to match against or a list\n * of patterns to match.\n * @param options -\n * The options for the search.\n *\n * @returns\n * A list of path strings that match the given patterns.\n */\n search(\n pattern: string | string[],\n options?: IZFileSystemSearchOptions,\n ): Promise<IZFileSystemNode[]>;\n\n /**\n * Walks up a directory tree to search for existence of a given path.\n *\n * @param search -\n * The path to search for. This is the candidate folder path that\n * may or may not exist somewhere from the start directory all the\n * way up the directory tree.\n * @param options -\n * The given options for the search.\n *\n * @returns\n * The fully qualified path to the first path that matches the search\n * starting at the options start or the current working directory if not\n * specified. Returns null if no such directory exists.\n *\n * @example\n *\n * ```ts\n * import { resolve } from 'path'\n *\n * // Find any folder named .vscode from the current working directory all the way\n * // up the directory tree. Returns null if no vscode directory can be found.\n * const service = new ZFileSystemService();\n * const vscode = service.walk('.vscode');\n *\n * // Walk the directory tree from the current script and find the .config folder.\n * const config = service.walk('.config', { start: __dirname });\n *\n * // Walk the directory tree from the current script and stop when we reach\n * // at most 2 directories up.\n * const start = __dirname;\n * const stop = resolve(__dirname, '../..');\n * const file = service.walk('path/to/file.json', { start, stop });\n * ```\n */\n walk(\n search: string,\n options?: IZFileSystemWalkOptions,\n ): Promise<string | null>;\n}\n\n/**\n * Represents a node implementation of a file system service.\n */\nexport class ZFileSystemService implements IZFileSystemService {\n public async info(path: string): Promise<IZFileSystemNode> {\n const [file] = await this.search(path);\n return file;\n }\n\n public async search(\n pattern: string | string[],\n options?: IZFileSystemSearchOptions,\n ): Promise<IZFileSystemNode[]> {\n const paths = await glob(pattern, {\n stat: true,\n ...options,\n withFileTypes: true,\n });\n\n return paths.map((path) => {\n let info = new ZFileSystemNodeBuilder()\n .path(path.fullpath())\n .created(path.birthtime)\n .updated(path.atime)\n .size(path.size);\n\n // Note that for folders, node will return the size of the underlying OS metadata,\n // hence, why we remove the size on the folder here.\n info = path.isFile() ? info.file() : info.folder().size(undefined);\n\n return info.build();\n });\n }\n\n public async walk(search: string, options?: IZFileSystemWalkOptions) {\n const start = options?.start || cwd();\n const stop = options?.stop || \"/\";\n const mode = options?.mode;\n\n const _test = async (path: string) => {\n try {\n await access(path, mode);\n return true;\n } catch {\n return false;\n }\n };\n\n if (isAbsolute(search)) {\n return (await _test(search)) ? search : null;\n }\n\n let dir = start;\n do {\n const path = resolve(dir, search);\n const exists = await _test(path);\n\n if (exists) {\n return path;\n }\n\n dir = dir === stop ? \"\" : dirname(dir);\n } while (dir.length);\n\n return null;\n }\n}\n","import type { FSWatcher } from \"chokidar\";\nimport { watch } from \"chokidar\";\nimport { type Stats } from \"node:fs\";\nimport { resolve } from \"node:path\";\nimport type { Observable } from \"rxjs\";\nimport { Subject } from \"rxjs\";\nimport {\n ZFileSystemNodeBuilder,\n type IZFileSystemNode,\n} from \"../file-system/file-system-node.mjs\";\n\n/**\n * Represents and object that can watch a folder or file on the file system.\n */\nexport interface IZFileWatch {\n /**\n * Starts the watch operation.\n */\n start(): Promise<void>;\n\n /**\n * Stops the watch operation.\n */\n stop(): Promise<void>;\n\n /**\n * The stream for files being added.\n *\n * This can only occur if the target being watched\n * is a folder.\n *\n * @returns\n * The observable that will publish files that\n * get added.\n */\n add(): Observable<IZFileSystemNode>;\n\n /**\n * The stream for files being updated.\n *\n * If this watcher points to a folder, then all files\n * recursively will send when they get updated. If this\n * watcher points to a file, then this will only invoke\n * when the file is updated.\n *\n * @returns\n * The observable that will publish files and folders\n * that are updated.\n */\n update(): Observable<IZFileSystemNode>;\n\n /**\n * The stream for files and folders being deleted.\n *\n * If this watcher points to a folder, then all files under the\n * folder will be sent through this observable, including the\n * folder being watched. If this points to a file, then\n * this will only receive when the file is unlinked.\n *\n * @returns\n * The observable that will publish file and folders\n * that are unlinked and removed respectively. Note\n * that files and folders streamed this way will not\n * have their stats set.\n */\n remove(): Observable<IZFileSystemNode>;\n}\n\n/**\n * An implementation of the IZFileWatch.\n */\nexport class ZFileWatch implements IZFileWatch {\n private _add: Subject<IZFileSystemNode> = new Subject<IZFileSystemNode>();\n private _update: Subject<IZFileSystemNode> = new Subject<IZFileSystemNode>();\n private _remove: Subject<IZFileSystemNode> = new Subject<IZFileSystemNode>();\n private _watcher: FSWatcher | undefined;\n\n /**\n * Initializes a new instance of this object.\n *\n * @param path -\n * The path to watch.\n */\n public constructor(public readonly path: string) {}\n\n public async start() {\n await this.stop();\n\n this._watcher = watch(this.path, {\n usePolling: true,\n alwaysStat: true,\n ignoreInitial: true,\n\n awaitWriteFinish: {\n stabilityThreshold: 500,\n pollInterval: 50,\n },\n });\n\n function next(\n observable: Subject<IZFileSystemNode>,\n file: string,\n stats: Stats | undefined,\n ) {\n const node = new ZFileSystemNodeBuilder().path(resolve(this.path, file));\n observable.next(stats ? node.stats(stats).build() : node.build());\n }\n\n this._watcher\n .on(\"add\", next.bind(this, this._add))\n .on(\"addDir\", next.bind(this, this._add))\n .on(\"change\", next.bind(this, this._update))\n .on(\"unlink\", next.bind(this, this._remove))\n .on(\"unlinkDir\", next.bind(this, this._remove));\n\n return new Promise<void>((resolve) =>\n this._watcher?.on(\"ready\", () => resolve()),\n );\n }\n\n public async stop() {\n await this._watcher?.close();\n delete this._watcher;\n }\n\n public add() {\n return this._add.asObservable();\n }\n\n public update() {\n return this._update.asObservable();\n }\n\n public remove() {\n return this._remove.asObservable();\n }\n}\n","import { firstDefined, sleep } from \"@zthun/helpful-fn\";\nimport type { IZDataRequest, IZDataSource } from \"@zthun/helpful-query\";\nimport { ZDataSourceStatic } from \"@zthun/helpful-query\";\nimport { find, findIndex, flatten, trimEnd, uniqBy } from \"lodash-es\";\nimport { minimatch } from \"minimatch\";\nimport { resolve, sep } from \"node:path\";\nimport type { Subscription } from \"rxjs\";\nimport {\n ZFileSystemNodeType,\n type IZFileSystemNode,\n} from \"../file-system/file-system-node.mjs\";\nimport {\n ZFileSystemService,\n type IZFileSystemService,\n} from \"../file-system/file-system-service.mjs\";\nimport { ZFileWatch, type IZFileWatch } from \"../file-watch/file-watch.mjs\";\n\n/**\n * Represents a repository for the file system.\n */\nexport interface IZFileRepository extends IZDataSource<IZFileSystemNode> {\n /**\n * Retrieves a single file from the repository.\n *\n * @param path -\n * The fully qualified path to the file.\n *\n * @returns\n * The node that represents the file. Returns null if no\n * such file exists.\n */\n get(path: string): Promise<IZFileSystemNode | null>;\n}\n\n/**\n * Represents an implementation of a ZFileRepository that watches\n * a given path scope.\n *\n * This repository is only concerned about files. Folders\n * will not be retrieved from this repository.\n */\nexport class ZFileRepository implements IZFileRepository {\n private _service: IZFileSystemService = new ZFileSystemService();\n private _watcher: IZFileWatch | undefined;\n private _nodes: Promise<ZDataSourceStatic<IZFileSystemNode>> =\n Promise.resolve(new ZDataSourceStatic<IZFileSystemNode>([]));\n private _globs: string[] = [\"**\"];\n private _path: string = \"\";\n private _add: Subscription | undefined;\n private _remove: Subscription | undefined;\n private _update: Subscription | undefined;\n\n /**\n * Gets the path that this repository is watching.\n */\n public get path() {\n return this._path;\n }\n\n /**\n * Gets the globs matchers that this repository is matching against.\n */\n public get globs() {\n return this._globs.slice();\n }\n\n /**\n * Initializes the repository with the given root and glob filter.\n *\n * This will initially scan the file system and setup watches.\n * If you call this method again, then the repository will be\n * {@link reset} and a new set of files will be added to the\n * repository.\n *\n * @param path -\n * The root path of the repository.\n * @param globs -\n * The optional relative globs of the repository. If this is falsy,\n * then ** is used. You can achieve the same kind of operation\n * using filters, but filtering out unwanted files frees up the internal\n * memory being used.\n */\n public async initialize(path: string, globs: string[] = [\"**\"]) {\n await this.reset();\n\n this._path = path;\n this._globs = globs;\n\n // Note that this all happens in the background and should\n // only be awaited later. So the search should not be\n // required to finish when existing this method. The only\n // requirement is that the repository is reset and the path +\n // glob scope is updated. Everything beyond here should not\n // be awaited - it will be awaited later once the caller\n // tries to retrieve the files using retrieve, get, or\n // count.\n const matches = globs.map((g) =>\n this._service.search(g, {\n cwd: path,\n stat: true,\n }),\n );\n\n this._nodes = Promise.all(matches)\n .then((nodes) => {\n const flat = flatten(nodes);\n const uniq = uniqBy(flat, (n) => n.path);\n return uniq.filter((n) => n.type === ZFileSystemNodeType.File);\n })\n .then((files) => {\n return new ZDataSourceStatic(files);\n });\n\n this._watcher = new ZFileWatch(path);\n\n this._add = this._watcher\n .add()\n .subscribe(async (node: IZFileSystemNode) => {\n if (\n node.type === ZFileSystemNodeType.File &&\n this._globs.some((g) => minimatch(node.path, resolve(this._path, g)))\n ) {\n const nodes = await this._nodes;\n this._nodes = nodes.insert(node);\n }\n });\n\n this._remove = this._watcher\n .remove()\n .subscribe(async (node: IZFileSystemNode) => {\n let nodes = await this._nodes;\n const path = trimEnd(node.path, sep);\n\n // It's possible that the node given was a folder. If that happens,\n // we need to remove all files that start with the given path.\n // If the node does point to a file, then there is no possibility that\n // more than 1 item would be removed.\n\n const next = async () =>\n findIndex(await nodes.items(), (n) => {\n return (\n n.path === path ||\n (n.path.startsWith(path) &&\n n.path.substring(path.length).charAt(0) === sep)\n );\n });\n\n for (let index = await next(); index >= 0; index = await next()) {\n nodes = await nodes.removeAt(index);\n }\n\n this._nodes = Promise.resolve(nodes);\n });\n\n this._update = this._watcher\n .update()\n .subscribe(async (node: IZFileSystemNode) => {\n const nodes = await this._nodes;\n const index = findIndex(\n await nodes.items(),\n (n) => n.path === node.path,\n );\n\n // It's possible node was filtered out by the globs, or\n // it is a directory. If so, then we won't have it in our\n // list.\n if (index >= 0) {\n const next = await nodes.removeAt(index);\n this._nodes = next.insert(node, index);\n }\n });\n\n // Kick off the initial seed operation with an even loop\n // invocation.\n await sleep(100);\n\n await this._watcher?.start();\n }\n\n /**\n * Resets the repository as if it was initially created.\n */\n public async reset(): Promise<void> {\n await this._watcher?.stop();\n\n this._add?.unsubscribe();\n this._remove?.unsubscribe();\n this._update?.unsubscribe();\n\n delete this._add;\n delete this._remove;\n delete this._update;\n delete this._watcher;\n\n this._path = \"\";\n this._globs = [\"**\"];\n this._nodes = Promise.resolve(new ZDataSourceStatic<IZFileSystemNode>([]));\n }\n\n public async get(path: string): Promise<IZFileSystemNode | null> {\n const nodes = await this._nodes;\n const items = await nodes.items();\n const node = find(items, (f) => f.path === path);\n\n return firstDefined(null, node);\n }\n\n public async count(request: IZDataRequest): Promise<number> {\n const source = await this._nodes;\n return source.count(request);\n }\n\n public async retrieve(request: IZDataRequest): Promise<IZFileSystemNode[]> {\n const source = await this._nodes;\n return source.retrieve(request);\n }\n}\n","import type { PathLike } from \"node:fs\";\nimport { resolve } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\n\nexport function resolvePathLike(path: PathLike): string {\n if (typeof path === \"string\") {\n return resolve(path);\n }\n\n if (path instanceof URL) {\n return fileURLToPath(path);\n }\n\n return resolve(path.toString());\n}\n","import { sleep } from \"@zthun/helpful-fn\";\n\n/**\n * The actual delay time that you should wait for a watch\n * operation to pick up your file changes.\n */\nexport const ZWatchDelay = 1500;\n\n/**\n * Performs a sleep long enough to allow a watch operation\n * to pick up a change.\n *\n * You should never really need this. Where it is useful\n * is for unit testing with IO operations and you want to\n * wait for your write operations to get picked up by\n * a file watch operation.\n */\nexport function sleepWatchDelay() {\n return sleep(ZWatchDelay);\n}\n","import type { PathLike } from \"fs\";\nimport { mkdir } from \"fs/promises\";\nimport type { IZStreamWrite } from \"./stream-write.mjs\";\n\n/**\n * A stream that writes folders.\n *\n * Writing folders is idempotent. If the folder you\n * are trying to write already exists, then the write\n * operation still succeeds\n */\nexport class ZStreamFolder implements IZStreamWrite {\n public async write(path: PathLike): Promise<number> {\n await mkdir(path, { recursive: true });\n\n return 0;\n }\n}\n","import type { PathLike, Stats } from \"node:fs\";\nimport { readFile, stat, writeFile } from \"node:fs/promises\";\nimport { dirname } from \"path\";\nimport { resolvePathLike } from \"../resolve-path-like/resolve-path-like.js\";\nimport { ZStreamFolder } from \"./stream-folder.mjs\";\nimport type { IZStreamRead, IZStreamReadOptions } from \"./stream-read.mjs\";\nimport type { IZStreamWrite, IZStreamWriteOptions } from \"./stream-write.mjs\";\n\n/**\n * Options for the stream file object.\n */\nexport interface IZStreamFileOptions {\n /**\n * Cache options.\n *\n * A warning that file content caching will take up significant memory\n * if the file size is too big or the max files is too big. Make sure\n * you know what you're doing when you change the default values of this.\n */\n cache?: {\n /**\n * Maximum number of bytes a file can be before it will not be cached.\n * The default is 100 Kib (102400 bytes)\n *\n * @default 102400\n */\n fileSize?: bigint;\n /**\n * The maximum number of files that are to be cached. The cache order\n * is first in, first out. Set this to 0 to not cache anything. The\n * default is 1000.\n *\n * @default 1000\n */\n maxFiles?: number;\n };\n}\n\n/**\n * A stream that can read and write to files.\n *\n * This is mostly a wrapper to readFile and writeFile from node, but\n * with some optimizations.\n *\n * First, this class supports file content caching so reading in a file\n * that's under a certain size threshold will store it in memory for\n * later retrieval.\n */\nexport class ZStreamFile implements IZStreamWrite, IZStreamRead {\n private static readonly FileSizeDefault = 102400; // One Hundred KibiBytes\n private static readonly MaxFilesDefault = 1000;\n\n private _cache = new Map<string, { stats: Stats; buffer: Promise<Buffer> }>();\n\n /**\n * Initializes a new instance of this object.\n *\n * @param options -\n * The options for file read and writes.\n */\n public constructor(public readonly options: IZStreamFileOptions = {}) {}\n\n public async read(\n path: PathLike,\n options?: IZStreamReadOptions,\n ): Promise<Buffer> {\n const _path = resolvePathLike(path);\n\n const stats = await stat(_path);\n const cached = this._cache.get(_path);\n\n const buffer =\n cached && cached.stats.mtimeMs >= stats.mtimeMs\n ? cached.buffer\n : readFile(_path, options);\n\n return this._addToCache(_path, { stats, buffer });\n }\n\n public async write(\n path: PathLike,\n { buffer = Buffer.from(\"\") }: IZStreamWriteOptions = {},\n ): Promise<number> {\n const _path = resolvePathLike(path);\n const directory = dirname(_path);\n\n await new ZStreamFolder().write(directory);\n await writeFile(_path, buffer, { flush: true });\n\n // If this file specifically was cached earlier,\n // we can just remove it now so we make room for\n // another file. Consumers can just read the\n // file again to recache it.\n this._cache.delete(_path);\n\n return buffer.length;\n }\n\n private _addToCache(\n path: string,\n item: { stats: Stats; buffer: Promise<Buffer> },\n ) {\n const { cache = {} } = this.options;\n const {\n fileSize = ZStreamFile.FileSizeDefault,\n maxFiles = ZStreamFile.MaxFilesDefault,\n } = cache;\n\n if (item.stats.size > fileSize) {\n // In this case, the file size is too big to cache in memory,\n // so we're bowing out here.\n return item.buffer;\n }\n\n // We will remove this path from the cache first since\n // we want it to be the most recent file (at the end)\n // of the key list. The removal does nothing if the\n // file was not cached.\n this._cache.delete(path);\n this._cache.set(path, item);\n\n if (this._cache.size > maxFiles) {\n // Retrieving the keys from a javascript map is order\n // by the time in which the keys are created. So\n // we are going to remove the first key which is the\n // oldest.\n const itr = this._cache.keys();\n this._cache.delete(itr.next().value);\n }\n\n return item.buffer;\n }\n}\n"],"names":["ZFileSystemNodeType","ZFileSystemNodeBuilder","created","at","_node","Date","toJSON","updated","size","bytes","BigInt","path","decorate","type","stats","s","builder","birthtime","mtime","isFile","file","folder","build","clone","structuredClone","omitBy","isUndefined","name","basename","extension","title","parent","dirname","extname","_define_property","bind","ZFileSystemService","info","search","pattern","options","paths","glob","stat","withFileTypes","map","fullpath","atime","undefined","walk","start","cwd","stop","mode","_test","access","isAbsolute","dir","resolve","exists","length","ZFileWatch","_watcher","watch","usePolling","alwaysStat","ignoreInitial","awaitWriteFinish","stabilityThreshold","pollInterval","next","observable","node","on","_add","_update","_remove","Promise","close","add","asObservable","update","remove","Subject","ZFileRepository","_path","globs","_globs","slice","initialize","reset","matches","g","_service","_nodes","all","then","nodes","flat","flatten","uniq","uniqBy","n","filter","File","files","ZDataSourceStatic","subscribe","some","minimatch","insert","trimEnd","sep","findIndex","items","startsWith","substring","charAt","index","removeAt","sleep","unsubscribe","get","find","f","firstDefined","count","request","source","retrieve","resolvePathLike","URL","fileURLToPath","toString","ZWatchDelay","sleepWatchDelay","ZStreamFolder","write","mkdir","recursive","ZStreamFile","read","cached","_cache","buffer","mtimeMs","readFile","_addToCache","Buffer","from","directory","writeFile","flush","delete","item","cache","fileSize","FileSizeDefault","maxFiles","MaxFilesDefault","set","itr","keys","value","Map"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAKA;;IAGO,IAAKA,mBAAAA,iBAAAA,SAAAA,mBAAAA,EAAAA;;;AAAAA,IAAAA,OAAAA,mBAAAA;AAGX,CAAA,CAAA,EAAA;AAwDD;;AAEC,IACM,MAAMC,sBAAAA,CAAAA;AAUJC,IAAAA,OAAAA,CAAQC,EAA8B,EAAE;QAC7C,IAAI,CAACC,KAAK,CAACF,OAAO,GAAGC,EAAAA,YAAcE,IAAAA,GAAOF,EAAAA,CAAGG,MAAM,EAAA,GAAKH,EAAAA;AAExD,QAAA,OAAO,IAAI;AACb,IAAA;AAEOI,IAAAA,OAAAA,CAAQJ,EAA8B,EAAE;QAC7C,IAAI,CAACC,KAAK,CAACG,OAAO,GAAGJ,EAAAA,YAAcE,IAAAA,GAAOF,EAAAA,CAAGG,MAAM,EAAA,GAAKH,EAAAA;AAExD,QAAA,OAAO,IAAI;AACb,IAAA;AAEOK,IAAAA,IAAAA,CAAKC,KAAkC,EAAE;QAC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QkD,IAAA;AAwEzE;AAnFE,gBAAA,CADWxB,WAAAA,EACaiB,iBAAAA,EAAkB,MAAA,CAAA,CAAA;AAC1C,gBAAA,CAFWjB,aAEamB,iBAAAA,EAAkB,IAAA,CAAA;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zthun/crumbtrail-fs",
3
- "version": "2.4.5",
3
+ "version": "2.4.6",
4
4
  "description": "A better file system module for node",
5
5
  "author": "Anthony Bonta",
6
6
  "license": "MIT",
@@ -28,12 +28,12 @@
28
28
  "access": "public"
29
29
  },
30
30
  "dependencies": {
31
- "@zthun/helpful-fn": "^9.11.4",
32
- "@zthun/helpful-query": "^9.11.4",
31
+ "@zthun/helpful-fn": "^9.11.5",
32
+ "@zthun/helpful-query": "^9.11.5",
33
33
  "chokidar": "^5.0.0",
34
- "glob": "^13.0.0",
34
+ "glob": "^13.0.1",
35
35
  "lodash-es": "^4.17.23",
36
- "minimatch": "^10.1.1",
36
+ "minimatch": "^10.1.2",
37
37
  "rxjs": "^7.8.2"
38
38
  },
39
39
  "devDependencies": {
@@ -48,5 +48,5 @@
48
48
  "dist"
49
49
  ],
50
50
  "sideEffects": false,
51
- "gitHead": "7db2da1265740eb140a5c46d9a8d42802db36146"
51
+ "gitHead": "b092744640cbefa05311c878cf8e79326347fa01"
52
52
  }