{"version":3,"file":"shared.cjs","names":[],"sources":["../src/shared/constants.ts","../src/shared/guards.ts","../src/shared/support.ts","../src/shared/tmp.ts"],"sourcesContent":["export { ABORT_ERROR, TIMEOUT_ERROR } from '@happy-ts/fetch-t';\n\n/**\n * A constant representing the error thrown when a file or directory is not found.\n * Name of DOMException.NOT_FOUND_ERR.\n *\n * @since 1.0.0\n */\nexport const NOT_FOUND_ERROR = 'NotFoundError' as const;\n\n/**\n * Response body is empty (null), typically from 204/304 responses or HEAD requests.\n *\n * @since 2.0.0\n */\nexport const EMPTY_BODY_ERROR = 'EmptyBodyError' as const;\n\n/**\n * File content is empty (0 bytes).\n *\n * @since 2.0.0\n */\nexport const EMPTY_FILE_ERROR = 'EmptyFileError' as const;\n\n/**\n * Nothing to zip - empty directory with no entries.\n *\n * @since 2.0.0\n */\nexport const NOTHING_TO_ZIP_ERROR = 'NothingToZipError' as const;\n\n/**\n * A constant representing the root directory path.\n *\n * @since 1.0.0\n */\nexport const ROOT_DIR = '/' as const;\n\n/**\n * A constant representing the temporary directory path.\n *\n * @since 1.7.0\n */\nexport const TMP_DIR = '/tmp' as const;","import type { FileSystemDirectoryHandleLike, FileSystemFileHandleLike, FileSystemHandleLike } from './defines.ts';\n\n/**\n * Checks whether the given handle is a file handle.\n *\n * @param handle - The `FileSystemHandle` to check.\n * @returns `true` if the handle is a `FileSystemFileHandle`, otherwise `false`.\n * @since 1.0.0\n * @see {@link isDirectoryHandle} for checking directory handles\n * @see {@link isFileHandleLike} for sync handle-like objects\n * @see {@link stat} for getting handles from paths\n * @example\n * ```typescript\n * (await stat('/path/to/file'))\n *     .inspect(handle => isFileHandle(handle) && console.log('This is a file'));\n * ```\n */\nexport function isFileHandle(handle: FileSystemHandle): handle is FileSystemFileHandle {\n    return handle.kind === 'file';\n}\n\n/**\n * Checks whether the given handle is a directory handle.\n *\n * @param handle - The `FileSystemHandle` to check.\n * @returns `true` if the handle is a `FileSystemDirectoryHandle`, otherwise `false`.\n * @since 1.0.0\n * @see {@link isFileHandle} for checking file handles\n * @see {@link stat} for getting handles from paths\n * @example\n * ```typescript\n * (await stat('/path/to/dir'))\n *     .inspect(handle => isDirectoryHandle(handle) && console.log('This is a directory'));\n * ```\n */\nexport function isDirectoryHandle(handle: FileSystemHandle): handle is FileSystemDirectoryHandle {\n    return handle.kind === 'directory';\n}\n\n/**\n * Checks whether the given handle-like object represents a file.\n *\n * @param handle - The `FileSystemHandleLike` object to check.\n * @returns `true` if the handle-like object represents a file, otherwise `false`.\n * @since 1.1.0\n * @see {@link isFileHandle} for async file handles\n * @see {@link statSync} for getting sync handle-like objects\n * @example\n * ```typescript\n * statSync('/path/to/file')\n *     .inspect(handle => isFileHandleLike(handle) && console.log(`File size: ${ handle.size }`));\n * ```\n */\nexport function isFileHandleLike(handle: FileSystemHandleLike): handle is FileSystemFileHandleLike {\n    return handle.kind === 'file';\n}\n\n/**\n * Checks whether the given handle-like object represents a directory.\n *\n * @param handle - The `FileSystemHandleLike` object to check.\n * @returns `true` if the handle-like object represents a directory, otherwise `false`.\n * @since 2.0.0\n * @see {@link isDirectoryHandle} for async directory handles\n * @see {@link isFileHandleLike} for checking file handle-like objects\n * @see {@link statSync} for getting sync handle-like objects\n * @example\n * ```typescript\n * statSync('/path/to/dir')\n *     .inspect(handle => isDirectoryHandleLike(handle) && console.log('This is a directory'));\n *\n * // Filter directories from readDirSync results\n * readDirSync('/documents')\n *     .inspect(entries => {\n *         const dirs = entries.filter(e => isDirectoryHandleLike(e.handle));\n *         console.log('Directories:', dirs.map(d => d.path));\n *     });\n * ```\n */\nexport function isDirectoryHandleLike(handle: FileSystemHandleLike): handle is FileSystemDirectoryHandleLike {\n    return handle.kind === 'directory';\n}\n","/**\n * Checks if the Origin Private File System (OPFS) is supported in the current environment.\n * OPFS requires a secure context (HTTPS or localhost) and browser support.\n *\n * @returns `true` if OPFS is supported, `false` otherwise.\n * @since 1.0.0\n * @see {@link isSyncChannelSupported} for checking sync channel support\n * @example\n * ```typescript\n * if (isOPFSSupported()) {\n *     // Use OPFS APIs\n *     const result = await readFile('/path/to/file');\n * } else {\n *     console.warn('OPFS is not supported in this environment');\n * }\n * ```\n */\nexport function isOPFSSupported(): boolean {\n    return typeof navigator?.storage?.getDirectory === 'function';\n}\n\n/**\n * Checks if the SyncChannel (synchronous file system operations) is supported.\n * SyncChannel requires `SharedArrayBuffer` and `Atomics` which are only available\n * in secure contexts with proper COOP/COEP headers.\n *\n * **Required HTTP headers for cross-origin isolation:**\n * ```\n * Cross-Origin-Opener-Policy: same-origin\n * Cross-Origin-Embedder-Policy: require-corp\n * ```\n *\n * @returns `true` if SyncChannel is supported, `false` otherwise.\n * @since 2.0.0\n * @see {@link isOPFSSupported} for checking OPFS support\n * @example\n * ```typescript\n * if (isSyncChannelSupported()) {\n *     // Use sync APIs\n *     const result = await SyncChannel.connect(worker);\n *     const content = readFileSync('/path/to/file');\n * } else {\n *     console.warn('SyncChannel requires cross-origin isolation');\n * }\n * ```\n */\nexport function isSyncChannelSupported(): boolean {\n    return typeof SharedArrayBuffer === 'function' && typeof Atomics === 'object';\n}","import { join, SEPARATOR } from '@std/path/posix';\nimport { TMP_DIR } from './constants.ts';\nimport type { TempOptions } from './defines.ts';\n\n/**\n * Generates a unique temporary file or directory path without creating it.\n * Uses `crypto.randomUUID()` to ensure uniqueness.\n *\n * @param options - Options for generating the temporary path.\n * @returns The generated temporary path string.\n * @since 1.7.0\n * @see {@link mkTemp} for creating the temporary file/directory\n * @see {@link isTempPath} for checking if a path is temporary\n * @example\n * ```typescript\n * generateTempPath();                           // '/tmp/tmp-550e8400-e29b-41d4-a716-446655440000'\n * generateTempPath({ basename: 'cache' });      // '/tmp/cache-550e8400-e29b-41d4-a716-446655440000'\n * generateTempPath({ extname: '.txt' });        // '/tmp/tmp-550e8400-e29b-41d4-a716-446655440000.txt'\n * generateTempPath({ isDirectory: true });      // '/tmp/tmp-550e8400-e29b-41d4-a716-446655440000'\n * ```\n */\nexport function generateTempPath(options?: TempOptions): string {\n    const {\n        isDirectory = false,\n        basename = 'tmp',\n        extname = '',\n    } = options ?? {};\n\n    const base = basename ? `${ basename }-` : '';\n    const ext = isDirectory ? '' : extname;\n\n    // use uuid to generate a unique name\n    return join(TMP_DIR, base + crypto.randomUUID() + ext);\n}\n\n/**\n * Checks whether the path is a temporary path (under `/tmp`).\n *\n * @param path - The path to check.\n * @returns `true` if the path starts with `/tmp/`, otherwise `false`.\n * @since 1.7.2\n * @see {@link generateTempPath} for generating temporary paths\n * @see {@link TMP_DIR} for the temporary directory constant\n * @example\n * ```typescript\n * isTempPath('/tmp/file.txt');  // true\n * isTempPath('/data/file.txt'); // false\n * ```\n */\nexport function isTempPath(path: string): boolean {\n    return path.startsWith(TMP_DIR + SEPARATOR);\n}\n"],"mappings":";;;;;;;;;;AAQA,MAAa,kBAAkB;;;;;;AAO/B,MAAa,mBAAmB;;;;;;AAOhC,MAAa,mBAAmB;;;;;;AAOhC,MAAa,uBAAuB;;;;;;AAOpC,MAAa,WAAW;;;;;;AAOxB,MAAa,UAAU;;;;;;;;;;;;;;;;;;AC1BvB,SAAgB,aAAa,QAA0D;CACnF,OAAO,OAAO,SAAS;AAC3B;;;;;;;;;;;;;;;AAgBA,SAAgB,kBAAkB,QAA+D;CAC7F,OAAO,OAAO,SAAS;AAC3B;;;;;;;;;;;;;;;AAgBA,SAAgB,iBAAiB,QAAkE;CAC/F,OAAO,OAAO,SAAS;AAC3B;;;;;;;;;;;;;;;;;;;;;;;AAwBA,SAAgB,sBAAsB,QAAuE;CACzG,OAAO,OAAO,SAAS;AAC3B;;;;;;;;;;;;;;;;;;;;AChEA,SAAgB,kBAA2B;CACvC,OAAO,OAAO,WAAW,SAAS,iBAAiB;AACvD;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,SAAgB,yBAAkC;CAC9C,OAAO,OAAO,sBAAsB,cAAc,OAAO,YAAY;AACzE;;;;;;;;;;;;;;;;;;;;AC3BA,SAAgB,iBAAiB,SAA+B;CAC5D,MAAM,EACF,cAAc,OACd,WAAW,OACX,UAAU,OACV,WAAW,CAAC;CAEhB,MAAM,OAAO,WAAW,GAAI,SAAU,KAAK;CAC3C,MAAM,MAAM,cAAc,KAAK;CAG/B,QAAA,GAAA,gBAAA,KAAA,CAAY,SAAS,OAAO,OAAO,WAAW,IAAI,GAAG;AACzD;;;;;;;;;;;;;;;AAgBA,SAAgB,WAAW,MAAuB;CAC9C,OAAO,KAAK,WAAW,UAAU,gBAAA,SAAS;AAC9C"}