@zenfs/core
Advanced tools
Comparing version 1.6.10 to 1.6.11
@@ -16,3 +16,3 @@ import { ErrnoError, Errno } from '../error.js'; | ||
for (const [optName, opt] of Object.entries(backend.options)) { | ||
const value = options?.[optName]; | ||
const value = options === null || options === void 0 ? void 0 : options[optName]; | ||
if (value === undefined || value === null) { | ||
@@ -19,0 +19,0 @@ if (!opt.required) { |
@@ -216,3 +216,3 @@ import { resolveMountConfig } from '../../config.js'; | ||
// Check for a `postMessage` function. | ||
if (typeof port?.postMessage != 'function') { | ||
if (typeof (port === null || port === void 0 ? void 0 : port.postMessage) != 'function') { | ||
throw new ErrnoError(Errno.EINVAL, 'option must be a port.'); | ||
@@ -219,0 +219,0 @@ } |
@@ -6,3 +6,3 @@ import { Stats, type StatsLike } from '../../stats.js'; | ||
*/ | ||
export declare const rootIno = 0n; | ||
export declare const rootIno: 0n; | ||
/** | ||
@@ -9,0 +9,0 @@ * Generic inode definition that can easily be serialized. |
@@ -46,3 +46,3 @@ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) { | ||
*/ | ||
export const rootIno = 0n; | ||
export const rootIno = BigInt(0); | ||
/** | ||
@@ -49,0 +49,0 @@ * Generic inode definition that can easily be serialized. |
@@ -95,7 +95,8 @@ import { checkOptions, isBackend, isBackendConfig } from './backends/backend.js'; | ||
export async function configure(configuration) { | ||
var _a, _b, _c; | ||
const uid = 'uid' in configuration ? configuration.uid || 0 : 0; | ||
const gid = 'gid' in configuration ? configuration.gid || 0 : 0; | ||
useCredentials({ uid, gid }); | ||
cache.stats.isEnabled = configuration.cacheStats ?? false; | ||
cache.paths.isEnabled = configuration.cachePaths ?? false; | ||
cache.stats.isEnabled = (_a = configuration.cacheStats) !== null && _a !== void 0 ? _a : false; | ||
cache.paths.isEnabled = (_b = configuration.cachePaths) !== null && _b !== void 0 ? _b : false; | ||
config.checkAccess = !configuration.disableAccessChecks; | ||
@@ -109,3 +110,3 @@ config.updateOnRead = !configuration.disableUpdateOnRead; | ||
if (isBackendConfig(mountConfig)) { | ||
mountConfig.disableAsyncCache ?? (mountConfig.disableAsyncCache = configuration.disableAsyncCache || false); | ||
(_c = mountConfig.disableAsyncCache) !== null && _c !== void 0 ? _c : (mountConfig.disableAsyncCache = configuration.disableAsyncCache || false); | ||
} | ||
@@ -112,0 +113,0 @@ if (point == '/') |
@@ -114,3 +114,4 @@ /* | ||
closeSync() { | ||
this.driver.close?.(this); | ||
var _a, _b; | ||
(_b = (_a = this.driver).close) === null || _b === void 0 ? void 0 : _b.call(_a, this); | ||
} | ||
@@ -122,3 +123,4 @@ close() { | ||
syncSync() { | ||
this.driver.sync?.(this); | ||
var _a, _b; | ||
(_b = (_a = this.driver).sync) === null || _b === void 0 ? void 0 : _b.call(_a, this); | ||
} | ||
@@ -163,6 +165,7 @@ sync() { | ||
createDevice(path, driver, options = {}) { | ||
var _a; | ||
if (this.existsSync(path)) { | ||
throw ErrnoError.With('EEXIST', path, 'mknod'); | ||
} | ||
let ino = 1n; | ||
let ino = BigInt(1); | ||
while (this.store.has(ino)) | ||
@@ -176,3 +179,3 @@ ino++; | ||
major: 0, | ||
...driver.init?.(ino, options), | ||
...(_a = driver.init) === null || _a === void 0 ? void 0 : _a.call(driver, ino, options), | ||
}; | ||
@@ -200,3 +203,4 @@ this.devices.set(path, dev); | ||
_createDevice(driver, options = {}) { | ||
let ino = 1n; | ||
var _a; | ||
let ino = BigInt(1); | ||
while (this.store.has(ino)) | ||
@@ -210,3 +214,3 @@ ino++; | ||
major: 0, | ||
...driver.init?.(ino, options), | ||
...(_a = driver.init) === null || _a === void 0 ? void 0 : _a.call(driver, ino, options), | ||
}; | ||
@@ -213,0 +217,0 @@ const path = '/' + (dev.name || driver.name) + (driver.singleton ? '' : this.devicesWithDriver(driver).length); |
@@ -113,3 +113,3 @@ import { Buffer } from 'buffer'; | ||
.stat() | ||
.then(stats => cb(undefined, typeof options == 'object' && options?.bigint ? new BigIntStats(stats) : stats)) | ||
.then(stats => cb(undefined, typeof options == 'object' && (options === null || options === void 0 ? void 0 : options.bigint) ? new BigIntStats(stats) : stats)) | ||
.catch(cb); | ||
@@ -433,3 +433,3 @@ } | ||
try { | ||
handle || (handle = await promises.open.call(context, path, 'r', options?.mode)); | ||
handle || (handle = await promises.open.call(context, path, 'r', options === null || options === void 0 ? void 0 : options.mode)); | ||
const result = await handle.read(new Uint8Array(size), 0, size, handle.file.position); | ||
@@ -443,3 +443,3 @@ stream.push(!result.bytesRead ? null : result.buffer.slice(0, result.bytesRead)); | ||
catch (error) { | ||
await handle?.close(); | ||
await (handle === null || handle === void 0 ? void 0 : handle.close()); | ||
stream.destroy(error); | ||
@@ -449,6 +449,3 @@ } | ||
destroy(error, callback) { | ||
handle | ||
?.close() | ||
.then(() => callback(error)) | ||
.catch(nop); | ||
handle === null || handle === void 0 ? void 0 : handle.close().then(() => callback(error)).catch(nop); | ||
}, | ||
@@ -472,6 +469,6 @@ }); | ||
const stream = new WriteStream({ | ||
highWaterMark: options?.highWaterMark, | ||
highWaterMark: options === null || options === void 0 ? void 0 : options.highWaterMark, | ||
async write(chunk, encoding, callback) { | ||
try { | ||
handle || (handle = await promises.open.call(context, path, 'w', options?.mode || 0o666)); | ||
handle || (handle = await promises.open.call(context, path, 'w', (options === null || options === void 0 ? void 0 : options.mode) || 0o666)); | ||
await handle.write(chunk, 0, encoding); | ||
@@ -481,3 +478,3 @@ callback(undefined); | ||
catch (error) { | ||
await handle?.close(); | ||
await (handle === null || handle === void 0 ? void 0 : handle.close()); | ||
callback(error); | ||
@@ -488,12 +485,6 @@ } | ||
callback(error); | ||
handle | ||
?.close() | ||
.then(() => callback(error)) | ||
.catch(callback); | ||
handle === null || handle === void 0 ? void 0 : handle.close().then(() => callback(error)).catch(callback); | ||
}, | ||
final(callback) { | ||
handle | ||
?.close() | ||
.then(() => callback()) | ||
.catch(callback); | ||
handle === null || handle === void 0 ? void 0 : handle.close().then(() => callback()).catch(callback); | ||
}, | ||
@@ -580,5 +571,5 @@ }); | ||
collectAsyncIterator(it) | ||
.then(results => callback(null, results ?? [])) | ||
.then(results => { var _a; return callback(null, (_a = results) !== null && _a !== void 0 ? _a : []); }) | ||
.catch((e) => callback(e)); | ||
} | ||
glob; |
@@ -67,7 +67,8 @@ import { Errno, ErrnoError } from '../error.js'; | ||
async _read() { | ||
var _a, _b; | ||
this.checkClosed(); | ||
this._entries ?? (this._entries = await readdir.call(this.context, this.path, { withFileTypes: true })); | ||
(_a = this._entries) !== null && _a !== void 0 ? _a : (this._entries = await readdir.call(this.context, this.path, { withFileTypes: true })); | ||
if (!this._entries.length) | ||
return null; | ||
return this._entries.shift() ?? null; | ||
return (_b = this._entries.shift()) !== null && _b !== void 0 ? _b : null; | ||
} | ||
@@ -86,7 +87,8 @@ read(cb) { | ||
readSync() { | ||
var _a, _b; | ||
this.checkClosed(); | ||
this._entries ?? (this._entries = readdirSync.call(this.context, this.path, { withFileTypes: true })); | ||
(_a = this._entries) !== null && _a !== void 0 ? _a : (this._entries = readdirSync.call(this.context, this.path, { withFileTypes: true })); | ||
if (!this._entries.length) | ||
return null; | ||
return this._entries.shift() ?? null; | ||
return (_b = this._entries.shift()) !== null && _b !== void 0 ? _b : null; | ||
} | ||
@@ -93,0 +95,0 @@ async next() { |
@@ -149,3 +149,3 @@ /* | ||
const joined = parts.join('/'); | ||
if (!joined?.length) | ||
if (!(joined === null || joined === void 0 ? void 0 : joined.length)) | ||
return '.'; | ||
@@ -152,0 +152,0 @@ return normalize(joined); |
@@ -166,3 +166,3 @@ var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) { | ||
buffer || (buffer = new Uint8Array((await this.file.stat()).size)); | ||
return this.file.read(buffer, offset ?? undefined, length ?? undefined, position ?? undefined); | ||
return this.file.read(buffer, offset !== null && offset !== void 0 ? offset : undefined, length !== null && length !== void 0 ? length : undefined, position !== null && position !== void 0 ? position : undefined); | ||
} | ||
@@ -233,3 +233,3 @@ async readFile(_options) { | ||
} | ||
return opts?.bigint ? new BigIntStats(stats) : stats; | ||
return (opts === null || opts === void 0 ? void 0 : opts.bigint) ? new BigIntStats(stats) : stats; | ||
} | ||
@@ -245,5 +245,5 @@ /** | ||
if (typeof options == 'object') { | ||
lenOrEnc = options?.length; | ||
position = options?.position; | ||
options = options?.offset; | ||
lenOrEnc = options === null || options === void 0 ? void 0 : options.length; | ||
position = options === null || options === void 0 ? void 0 : options.position; | ||
options = options === null || options === void 0 ? void 0 : options.offset; | ||
} | ||
@@ -263,3 +263,3 @@ if (typeof data === 'string') { | ||
} | ||
position ?? (position = this.file.position); | ||
position !== null && position !== void 0 ? position : (position = this.file.position); | ||
const bytesWritten = await this.file.write(buffer, offset, length, position); | ||
@@ -331,3 +331,3 @@ emitChange('change', this.file.path); | ||
const stream = new ReadStream({ | ||
highWaterMark: options?.highWaterMark || 64 * 1024, | ||
highWaterMark: (options === null || options === void 0 ? void 0 : options.highWaterMark) || 64 * 1024, | ||
encoding: options.encoding, | ||
@@ -355,4 +355,4 @@ // eslint-disable-next-line @typescript-eslint/no-misused-promises | ||
const streamOptions = { | ||
highWaterMark: options?.highWaterMark, | ||
encoding: options?.encoding, | ||
highWaterMark: options === null || options === void 0 ? void 0 : options.highWaterMark, | ||
encoding: options === null || options === void 0 ? void 0 : options.encoding, | ||
write: async (chunk, encoding, callback) => { | ||
@@ -420,3 +420,3 @@ try { | ||
} | ||
return options?.bigint ? new BigIntStats(stats) : stats; | ||
return (options === null || options === void 0 ? void 0 : options.bigint) ? new BigIntStats(stats) : stats; | ||
} | ||
@@ -433,3 +433,3 @@ catch (e) { | ||
const stats = await fs.stat(resolved); | ||
return options?.bigint ? new BigIntStats(stats) : stats; | ||
return (options === null || options === void 0 ? void 0 : options.bigint) ? new BigIntStats(stats) : stats; | ||
} | ||
@@ -630,4 +630,5 @@ catch (e) { | ||
export async function mkdir(path, options) { | ||
var _a; | ||
options = typeof options === 'object' ? options : { mode: options }; | ||
const mode = normalizeMode(options?.mode, 0o777); | ||
const mode = normalizeMode(options === null || options === void 0 ? void 0 : options.mode, 0o777); | ||
path = await realpath.call(this, path); | ||
@@ -637,3 +638,3 @@ const { fs, path: resolved, root } = resolveMount(path, this); | ||
try { | ||
if (!options?.recursive) { | ||
if (!(options === null || options === void 0 ? void 0 : options.recursive)) { | ||
if (config.checkAccess && !(await fs.stat(dirname(resolved))).hasAccess(constants.W_OK, this)) { | ||
@@ -658,3 +659,3 @@ throw ErrnoError.With('EACCES', dirname(resolved), 'mkdir'); | ||
} | ||
return root.length == 1 ? dirs[0] : dirs[0]?.slice(root.length); | ||
return root.length == 1 ? dirs[0] : (_a = dirs[0]) === null || _a === void 0 ? void 0 : _a.slice(root.length); | ||
} | ||
@@ -689,3 +690,3 @@ catch (e) { | ||
let entryStats; | ||
if (options?.recursive || options?.withFileTypes) { | ||
if ((options === null || options === void 0 ? void 0 : options.recursive) || (options === null || options === void 0 ? void 0 : options.withFileTypes)) { | ||
const _entryStats = cache.stats.getAsync(join(path, entry)) || fs.stat(join(resolved, entry)).catch(handleError); | ||
@@ -695,6 +696,6 @@ cache.stats.setAsync(join(path, entry), _entryStats); | ||
} | ||
if (options?.withFileTypes) { | ||
if (options === null || options === void 0 ? void 0 : options.withFileTypes) { | ||
values.push(new Dirent(entry, entryStats)); | ||
} | ||
else if (options?.encoding == 'buffer') { | ||
else if ((options === null || options === void 0 ? void 0 : options.encoding) == 'buffer') { | ||
values.push(Buffer.from(entry)); | ||
@@ -705,3 +706,3 @@ } | ||
} | ||
if (!options?.recursive || !entryStats?.isDirectory()) | ||
if (!(options === null || options === void 0 ? void 0 : options.recursive) || !(entryStats === null || entryStats === void 0 ? void 0 : entryStats.isDirectory())) | ||
return; | ||
@@ -723,3 +724,3 @@ for (const subEntry of await readdir.call(this, join(path, entry), { ...options, _isIndirect: true })) { | ||
await Promise.all(entries.map(addEntry)); | ||
if (!options?._isIndirect) { | ||
if (!(options === null || options === void 0 ? void 0 : options._isIndirect)) { | ||
cache.stats.clear(); | ||
@@ -790,5 +791,5 @@ } | ||
const value = await handle.readFile(); | ||
const encoding = typeof options == 'object' ? options?.encoding : options; | ||
const encoding = typeof options == 'object' ? options === null || options === void 0 ? void 0 : options.encoding : options; | ||
// always defaults to utf-8 to avoid wrangler (cloudflare) worker "unknown encoding" exception | ||
return encoding == 'buffer' ? value : value.toString((encoding ?? 'utf-8')); | ||
return encoding == 'buffer' ? value : value.toString((encoding !== null && encoding !== void 0 ? encoding : 'utf-8')); | ||
} | ||
@@ -916,7 +917,7 @@ catch (e_6) { | ||
path = normalizePath(path); | ||
const ctx_path = (this?.root || '') + path; | ||
const ctx_path = ((this === null || this === void 0 ? void 0 : this.root) || '') + path; | ||
if (cache.paths.hasAsync(ctx_path)) | ||
return cache.paths.getAsync(ctx_path); | ||
const { base, dir } = parse(path); | ||
const realDir = dir == '/' ? '/' : await (cache.paths.getAsync((this?.root || '') + dir) || realpath.call(this, dir)); | ||
const realDir = dir == '/' ? '/' : await (cache.paths.getAsync(((this === null || this === void 0 ? void 0 : this.root) || '') + dir) || realpath.call(this, dir)); | ||
const lpath = join(realDir, base); | ||
@@ -932,3 +933,3 @@ const { fs, path: resolvedPath } = resolveMount(lpath, this); | ||
const target = resolve(realDir, (await readlink.call(this, lpath)).toString()); | ||
const real = cache.paths.getAsync((this?.root || '') + target) || realpath.call(this, target); | ||
const real = cache.paths.getAsync(((this === null || this === void 0 ? void 0 : this.root) || '') + target) || realpath.call(this, target); | ||
cache.paths.setAsync(ctx_path, real); | ||
@@ -952,3 +953,4 @@ return await real; | ||
watcher.on('change', (eventType, filename) => { | ||
eventQueue.shift()?.({ value: { eventType, filename }, done: false }); | ||
var _a; | ||
(_a = eventQueue.shift()) === null || _a === void 0 ? void 0 : _a({ value: { eventType, filename }, done: false }); | ||
}); | ||
@@ -996,3 +998,3 @@ function cleanup() { | ||
lstat.call(this, path).catch((error) => { | ||
if (error.code == 'ENOENT' && options?.force) | ||
if (error.code == 'ENOENT' && (options === null || options === void 0 ? void 0 : options.force)) | ||
return undefined; | ||
@@ -1007,3 +1009,3 @@ throw error; | ||
case constants.S_IFDIR: | ||
if (options?.recursive) { | ||
if (options === null || options === void 0 ? void 0 : options.recursive) { | ||
for (const entry of await readdir.call(this, path, { _isIndirect: true })) { | ||
@@ -1027,3 +1029,3 @@ await rm.call(this, join(path, entry), { ...options, _isIndirect: true }); | ||
} | ||
if (!options?._isIndirect) { | ||
if (!(options === null || options === void 0 ? void 0 : options._isIndirect)) { | ||
cache.stats.clear(); | ||
@@ -1034,3 +1036,3 @@ } | ||
export async function mkdtemp(prefix, options) { | ||
const encoding = typeof options === 'object' ? options?.encoding : options || 'utf8'; | ||
const encoding = typeof options === 'object' ? options === null || options === void 0 ? void 0 : options.encoding : options || 'utf8'; | ||
const fsName = `${prefix}${Date.now()}-${Math.random().toString(36).slice(2)}`; | ||
@@ -1087,3 +1089,3 @@ const resolvedPath = '/tmp/' + fsName; | ||
const srcStats = await lstat.call(this, source); // Use lstat to follow symlinks if not dereferencing | ||
if (opts?.errorOnExist && (await exists.call(this, destination))) { | ||
if ((opts === null || opts === void 0 ? void 0 : opts.errorOnExist) && (await exists.call(this, destination))) { | ||
throw new ErrnoError(Errno.EEXIST, 'Destination file or directory already exists.', destination, 'cp'); | ||
@@ -1093,3 +1095,3 @@ } | ||
case constants.S_IFDIR: { | ||
if (!opts?.recursive) { | ||
if (!(opts === null || opts === void 0 ? void 0 : opts.recursive)) { | ||
throw new ErrnoError(Errno.EISDIR, source + ' is a directory (not copied)', source, 'cp'); | ||
@@ -1120,3 +1122,3 @@ } | ||
// Optionally preserve timestamps | ||
if (opts?.preserveTimestamps) { | ||
if (opts === null || opts === void 0 ? void 0 : opts.preserveTimestamps) { | ||
await utimes.call(this, destination, srcStats.atime, srcStats.mtime); | ||
@@ -1129,3 +1131,3 @@ } | ||
const { fs } = resolveMount(path, this); | ||
return Promise.resolve(_statfs(fs, opts?.bigint)); | ||
return Promise.resolve(_statfs(fs, opts === null || opts === void 0 ? void 0 : opts.bigint)); | ||
} | ||
@@ -1132,0 +1134,0 @@ export function glob(pattern, opt) { |
@@ -73,3 +73,3 @@ // Utilities and shared data | ||
export function resolveMount(path, ctx) { | ||
const root = ctx?.root || '/'; | ||
const root = (ctx === null || ctx === void 0 ? void 0 : ctx.root) || '/'; | ||
path = normalizePath(join(root, path)); | ||
@@ -95,3 +95,3 @@ const sortedMounts = [...mounts].sort((a, b) => (a[0].length > b[0].length ? -1 : 1)); // descending order of the string length | ||
for (const [from, to] of Object.entries(paths)) { | ||
text = text?.replaceAll(from, to); | ||
text = text === null || text === void 0 ? void 0 : text.replaceAll(from, to); | ||
} | ||
@@ -146,4 +146,4 @@ return text; | ||
export function chroot(path, inPlace) { | ||
const creds = this?.credentials; | ||
if (creds?.uid && creds?.gid && creds?.euid && creds?.egid) { | ||
const creds = this === null || this === void 0 ? void 0 : this.credentials; | ||
if ((creds === null || creds === void 0 ? void 0 : creds.uid) && (creds === null || creds === void 0 ? void 0 : creds.gid) && (creds === null || creds === void 0 ? void 0 : creds.euid) && (creds === null || creds === void 0 ? void 0 : creds.egid)) { | ||
throw new ErrnoError(Errno.EPERM, 'Can not chroot() as non-root user'); | ||
@@ -155,3 +155,3 @@ } | ||
} | ||
return bindContext(join(this?.root || '/', path), creds); | ||
return bindContext(join((this === null || this === void 0 ? void 0 : this.root) || '/', path), creds); | ||
} | ||
@@ -158,0 +158,0 @@ /** |
@@ -114,3 +114,3 @@ var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) { | ||
} | ||
return options?.bigint ? new BigIntStats(stats) : stats; | ||
return (options === null || options === void 0 ? void 0 : options.bigint) ? new BigIntStats(stats) : stats; | ||
} | ||
@@ -127,3 +127,3 @@ catch (e) { | ||
const stats = fs.statSync(resolved); | ||
return options?.bigint ? new BigIntStats(stats) : stats; | ||
return (options === null || options === void 0 ? void 0 : options.bigint) ? new BigIntStats(stats) : stats; | ||
} | ||
@@ -311,3 +311,3 @@ catch (e) { | ||
const stats = fd2file(fd).statSync(); | ||
return options?.bigint ? new BigIntStats(stats) : stats; | ||
return (options === null || options === void 0 ? void 0 : options.bigint) ? new BigIntStats(stats) : stats; | ||
} | ||
@@ -354,3 +354,3 @@ fstatSync; | ||
const file = fd2file(fd); | ||
position ?? (position = file.position); | ||
position !== null && position !== void 0 ? position : (position = file.position); | ||
const bytesWritten = file.writeSync(buffer, offset, length, position); | ||
@@ -422,4 +422,5 @@ emitChange('change', file.path); | ||
export function mkdirSync(path, options) { | ||
var _a; | ||
options = typeof options === 'object' ? options : { mode: options }; | ||
const mode = normalizeMode(options?.mode, 0o777); | ||
const mode = normalizeMode(options === null || options === void 0 ? void 0 : options.mode, 0o777); | ||
path = realpathSync.call(this, path); | ||
@@ -429,3 +430,3 @@ const { fs, path: resolved, root } = resolveMount(path, this); | ||
try { | ||
if (!options?.recursive) { | ||
if (!(options === null || options === void 0 ? void 0 : options.recursive)) { | ||
if (config.checkAccess && !fs.statSync(dirname(resolved)).hasAccess(constants.W_OK, this)) { | ||
@@ -448,3 +449,3 @@ throw ErrnoError.With('EACCES', dirname(resolved), 'mkdir'); | ||
} | ||
return root.length == 1 ? dirs[0] : dirs[0]?.slice(root.length); | ||
return root.length == 1 ? dirs[0] : (_a = dirs[0]) === null || _a === void 0 ? void 0 : _a.slice(root.length); | ||
} | ||
@@ -480,6 +481,6 @@ catch (e) { | ||
cache.stats.set(join(path, entry), entryStat); | ||
if (options?.withFileTypes) { | ||
if (options === null || options === void 0 ? void 0 : options.withFileTypes) { | ||
values.push(new Dirent(entry, entryStat)); | ||
} | ||
else if (options?.encoding == 'buffer') { | ||
else if ((options === null || options === void 0 ? void 0 : options.encoding) == 'buffer') { | ||
values.push(Buffer.from(entry)); | ||
@@ -490,3 +491,3 @@ } | ||
} | ||
if (!entryStat.isDirectory() || !options?.recursive) | ||
if (!entryStat.isDirectory() || !(options === null || options === void 0 ? void 0 : options.recursive)) | ||
continue; | ||
@@ -506,3 +507,3 @@ for (const subEntry of readdirSync.call(this, join(path, entry), { ...options, _isIndirect: true })) { | ||
} | ||
if (!options?._isIndirect) { | ||
if (!(options === null || options === void 0 ? void 0 : options._isIndirect)) { | ||
cache.stats.clear(); | ||
@@ -558,3 +559,3 @@ } | ||
const value = Buffer.from(_readFileSync.call(this, path.toString(), 'r', false)); | ||
const encoding = typeof options == 'object' ? options?.encoding : options; | ||
const encoding = typeof options == 'object' ? options === null || options === void 0 ? void 0 : options.encoding : options; | ||
if (encoding == 'buffer') { | ||
@@ -564,3 +565,3 @@ return value; | ||
// always defaults to utf-8 to avoid wrangler (cloudflare) worker "unknown encoding" exception | ||
return value.toString(encoding ?? 'utf-8'); | ||
return value.toString(encoding !== null && encoding !== void 0 ? encoding : 'utf-8'); | ||
} | ||
@@ -612,7 +613,7 @@ readlinkSync; | ||
path = normalizePath(path); | ||
const ctx_path = (this?.root || '') + path; | ||
const ctx_path = ((this === null || this === void 0 ? void 0 : this.root) || '') + path; | ||
if (cache.paths.has(ctx_path)) | ||
return cache.paths.get(ctx_path); | ||
const { base, dir } = parse(path); | ||
const realDir = dir == '/' ? '/' : cache.paths.get((this?.root || '') + dir) || realpathSync.call(this, dir); | ||
const realDir = dir == '/' ? '/' : cache.paths.get(((this === null || this === void 0 ? void 0 : this.root) || '') + dir) || realpathSync.call(this, dir); | ||
const lpath = join(realDir, base); | ||
@@ -628,3 +629,3 @@ const { fs, path: resolvedPath } = resolveMount(lpath, this); | ||
const target = resolve(realDir, readlinkSync.call(this, lpath, options).toString()); | ||
const real = cache.paths.get((this?.root || '') + target) || realpathSync.call(this, target); | ||
const real = cache.paths.get(((this === null || this === void 0 ? void 0 : this.root) || '') + target) || realpathSync.call(this, target); | ||
cache.paths.set(ctx_path, real); | ||
@@ -660,3 +661,3 @@ return real; | ||
catch (error) { | ||
if (error.code != 'ENOENT' || !options?.force) | ||
if (error.code != 'ENOENT' || !(options === null || options === void 0 ? void 0 : options.force)) | ||
throw error; | ||
@@ -670,3 +671,3 @@ } | ||
case constants.S_IFDIR: | ||
if (options?.recursive) { | ||
if (options === null || options === void 0 ? void 0 : options.recursive) { | ||
for (const entry of readdirSync.call(this, path, { _isIndirect: true })) { | ||
@@ -690,3 +691,3 @@ rmSync.call(this, join(path, entry), { ...options, _isIndirect: true }); | ||
} | ||
if (!options?._isIndirect) { | ||
if (!(options === null || options === void 0 ? void 0 : options._isIndirect)) { | ||
cache.stats.clear(); | ||
@@ -697,3 +698,3 @@ } | ||
export function mkdtempSync(prefix, options) { | ||
const encoding = typeof options === 'object' ? options?.encoding : options || 'utf8'; | ||
const encoding = typeof options === 'object' ? options === null || options === void 0 ? void 0 : options.encoding : options || 'utf8'; | ||
const fsName = `${prefix}${Date.now()}-${Math.random().toString(36).slice(2)}`; | ||
@@ -780,3 +781,3 @@ const resolvedPath = '/tmp/' + fsName; | ||
const srcStats = lstatSync.call(this, source); // Use lstat to follow symlinks if not dereferencing | ||
if (opts?.errorOnExist && existsSync.call(this, destination)) { | ||
if ((opts === null || opts === void 0 ? void 0 : opts.errorOnExist) && existsSync.call(this, destination)) { | ||
throw new ErrnoError(Errno.EEXIST, 'Destination file or directory already exists.', destination, 'cp'); | ||
@@ -786,3 +787,3 @@ } | ||
case constants.S_IFDIR: | ||
if (!opts?.recursive) { | ||
if (!(opts === null || opts === void 0 ? void 0 : opts.recursive)) { | ||
throw new ErrnoError(Errno.EISDIR, source + ' is a directory (not copied)', source, 'cp'); | ||
@@ -810,3 +811,3 @@ } | ||
// Optionally preserve timestamps | ||
if (opts?.preserveTimestamps) { | ||
if (opts === null || opts === void 0 ? void 0 : opts.preserveTimestamps) { | ||
utimesSync.call(this, destination, srcStats.atime, srcStats.mtime); | ||
@@ -819,3 +820,3 @@ } | ||
const { fs } = resolveMount(path, this); | ||
return _statfs(fs, options?.bigint); | ||
return _statfs(fs, options === null || options === void 0 ? void 0 : options.bigint); | ||
} | ||
@@ -822,0 +823,0 @@ export function globSync(pattern, options = {}) { |
@@ -370,3 +370,3 @@ import { config } from './emulation/config.js'; | ||
this.stats.atimeMs = Date.now(); | ||
position ?? (position = this.position); | ||
position !== null && position !== void 0 ? position : (position = this.position); | ||
let end = position + length; | ||
@@ -373,0 +373,0 @@ if (end > this.stats.size) { |
@@ -13,2 +13,3 @@ import { ZenFsType } from './stats.js'; | ||
metadata() { | ||
var _a; | ||
return { | ||
@@ -20,3 +21,3 @@ name: this.constructor.name.toLowerCase(), | ||
noResizableBuffers: false, | ||
noAsyncCache: this._disableSync ?? false, | ||
noAsyncCache: (_a = this._disableSync) !== null && _a !== void 0 ? _a : false, | ||
type: ZenFsType, | ||
@@ -23,0 +24,0 @@ }; |
@@ -1,5 +0,3 @@ | ||
import { type File } from '../file.js'; | ||
import type { FileSystem } from '../filesystem.js'; | ||
import type { Stats } from '../stats.js'; | ||
import type { AsyncFSMethods, Mixin } from './shared.js'; | ||
import type { _SyncFSKeys, AsyncFSMethods, Mixin } from './shared.js'; | ||
/** @internal */ | ||
@@ -12,3 +10,3 @@ export type AsyncOperation = { | ||
*/ | ||
export interface AsyncMixin { | ||
export interface AsyncMixin extends Pick<FileSystem, Exclude<_SyncFSKeys, 'existsSync'>> { | ||
/** | ||
@@ -20,12 +18,2 @@ * @internal @protected | ||
ready(): Promise<void>; | ||
renameSync(oldPath: string, newPath: string): void; | ||
statSync(path: string): Stats; | ||
createFileSync(path: string, flag: string, mode: number): File; | ||
openFileSync(path: string, flag: string): File; | ||
unlinkSync(path: string): void; | ||
rmdirSync(path: string): void; | ||
mkdirSync(path: string, mode: number): void; | ||
readdirSync(path: string): string[]; | ||
linkSync(srcpath: string, dstpath: string): void; | ||
syncSync(path: string, data: Uint8Array, stats: Readonly<Stats>): void; | ||
} | ||
@@ -32,0 +20,0 @@ /** |
@@ -69,10 +69,2 @@ var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) { | ||
class AsyncFS extends FS { | ||
constructor() { | ||
super(...arguments); | ||
/** | ||
* Queue of pending asynchronous operations. | ||
*/ | ||
this._queue = []; | ||
this._isInitialized = false; | ||
} | ||
get _queueRunning() { | ||
@@ -87,2 +79,11 @@ return !!this._queue.length; | ||
} | ||
constructor(...args) { | ||
super(...args); | ||
/** | ||
* Queue of pending asynchronous operations. | ||
*/ | ||
this._queue = []; | ||
this._isInitialized = false; | ||
this._patchAsync(); | ||
} | ||
async ready() { | ||
@@ -236,4 +237,30 @@ await super.ready(); | ||
} | ||
/** | ||
* @internal | ||
* Patch all async methods to also call their synchronous counterparts unless called from the queue | ||
*/ | ||
_patchAsync() { | ||
const asyncFSMethodKeys = ['rename', 'stat', 'createFile', 'openFile', 'unlink', 'rmdir', 'mkdir', 'readdir', 'link', 'sync', 'exists']; | ||
for (const key of asyncFSMethodKeys) { | ||
if (typeof this[key] !== 'function') | ||
continue; | ||
const originalMethod = this[key]; | ||
this[key] = async (...args) => { | ||
var _a, _b; | ||
const result = await originalMethod.apply(this, args); | ||
if (new Error().stack.includes(`at async ${this.constructor.name}._next`)) | ||
return result; | ||
try { | ||
// @ts-expect-error 2556 | ||
(_b = (_a = this._sync) === null || _a === void 0 ? void 0 : _a[`${key}Sync`]) === null || _b === void 0 ? void 0 : _b.call(_a, ...args); | ||
} | ||
catch (e) { | ||
throw new ErrnoError(e.errno, 'Out of sync! (' + e.message + ')', args[0], key); | ||
} | ||
return result; | ||
}; | ||
} | ||
} | ||
} | ||
return AsyncFS; | ||
} |
@@ -65,3 +65,4 @@ var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) { | ||
async done() { | ||
await this.previous?.done(); | ||
var _a; | ||
await ((_a = this.previous) === null || _a === void 0 ? void 0 : _a.done()); | ||
await this.current.promise; | ||
@@ -107,7 +108,7 @@ } | ||
const error = ErrnoError.With('EDEADLK', path, syscall); | ||
error.stack += stack?.slice('Error'.length); | ||
error.stack += stack === null || stack === void 0 ? void 0 : stack.slice('Error'.length); | ||
throw error; | ||
} | ||
}, 5000); | ||
await previous?.done(); | ||
await (previous === null || previous === void 0 ? void 0 : previous.done()); | ||
return lock; | ||
@@ -121,3 +122,4 @@ } | ||
lockSync(path, syscall) { | ||
if (this.currentLock?.isLocked) { | ||
var _a; | ||
if ((_a = this.currentLock) === null || _a === void 0 ? void 0 : _a.isLocked) { | ||
throw ErrnoError.With('EBUSY', path, syscall); | ||
@@ -132,3 +134,4 @@ } | ||
get isLocked() { | ||
return !!this.currentLock?.isLocked; | ||
var _a; | ||
return !!((_a = this.currentLock) === null || _a === void 0 ? void 0 : _a.isLocked); | ||
} | ||
@@ -135,0 +138,0 @@ /* eslint-disable @typescript-eslint/no-unused-vars */ |
@@ -9,6 +9,18 @@ import type { ExtractProperties } from 'utilium'; | ||
/** | ||
* Asynchronous `FileSystem` methods. This is a convenience type. | ||
* @internal @hidden | ||
* Note this include `existsSync`, even though it is a concrete method. | ||
*/ | ||
export type _SyncFSKeys = Exclude<Extract<keyof FileSystem, `${string}Sync`>, '_disableSync'>; | ||
/** | ||
* @internal @hidden | ||
* Note this include `exists`, even though it is a concrete method. | ||
*/ | ||
export type _AsyncFSKeys = { | ||
[K in _SyncFSKeys]: K extends `${infer T}Sync` ? T : never; | ||
}[_SyncFSKeys]; | ||
/** | ||
* Asynchronous `FileSystem` methods. This is a convenience type for all of the async operations. | ||
* @internal | ||
*/ | ||
export type AsyncFSMethods = ExtractProperties<FileSystem, (...args: any[]) => Promise<unknown>>; | ||
export type AsyncFSMethods = Pick<FileSystem, _AsyncFSKeys>; | ||
/** | ||
@@ -15,0 +27,0 @@ * Concrete `FileSystem`. This is a convenience type. |
@@ -0,3 +1,4 @@ | ||
var _a, _b, _c; | ||
// eslint-disable-next-line @typescript-eslint/unbound-method | ||
Promise.withResolvers ?? (Promise.withResolvers = function () { | ||
(_a = Promise.withResolvers) !== null && _a !== void 0 ? _a : (Promise.withResolvers = function () { | ||
let _resolve, | ||
@@ -13,5 +14,5 @@ // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
// @ts-expect-error 2540 | ||
Symbol['dispose'] ?? (Symbol['dispose'] = Symbol('Symbol.dispose')); | ||
(_b = Symbol['dispose']) !== null && _b !== void 0 ? _b : (Symbol['dispose'] = Symbol('Symbol.dispose')); | ||
// @ts-expect-error 2540 | ||
Symbol['asyncDispose'] ?? (Symbol['asyncDispose'] = Symbol('Symbol.asyncDispose')); | ||
(_c = Symbol['asyncDispose']) !== null && _c !== void 0 ? _c : (Symbol['asyncDispose'] = Symbol('Symbol.asyncDispose')); | ||
export {}; |
import { credentials } from './credentials.js'; | ||
import { R_OK, S_IFBLK, S_IFCHR, S_IFDIR, S_IFIFO, S_IFLNK, S_IFMT, S_IFREG, S_IFSOCK, S_IRGRP, S_IROTH, S_IRUSR, S_IWGRP, S_IWOTH, S_IWUSR, S_IXGRP, S_IXOTH, S_IXUSR, size_max, W_OK, X_OK, } from './emulation/constants.js'; | ||
const n1000 = BigInt(1000); | ||
/** | ||
@@ -71,11 +72,11 @@ * Provides information about a particular entry in the file system. | ||
const now = Date.now(); | ||
this.atimeMs = this._convert(atimeMs ?? now); | ||
this.mtimeMs = this._convert(mtimeMs ?? now); | ||
this.ctimeMs = this._convert(ctimeMs ?? now); | ||
this.birthtimeMs = this._convert(birthtimeMs ?? now); | ||
this.uid = this._convert(uid ?? 0); | ||
this.gid = this._convert(gid ?? 0); | ||
this.size = this._convert(size ?? 0); | ||
this.ino = this._convert(ino ?? 0); | ||
this.mode = this._convert(mode ?? 0o644 & S_IFREG); | ||
this.atimeMs = this._convert(atimeMs !== null && atimeMs !== void 0 ? atimeMs : now); | ||
this.mtimeMs = this._convert(mtimeMs !== null && mtimeMs !== void 0 ? mtimeMs : now); | ||
this.ctimeMs = this._convert(ctimeMs !== null && ctimeMs !== void 0 ? ctimeMs : now); | ||
this.birthtimeMs = this._convert(birthtimeMs !== null && birthtimeMs !== void 0 ? birthtimeMs : now); | ||
this.uid = this._convert(uid !== null && uid !== void 0 ? uid : 0); | ||
this.gid = this._convert(gid !== null && gid !== void 0 ? gid : 0); | ||
this.size = this._convert(size !== null && size !== void 0 ? size : 0); | ||
this.ino = this._convert(ino !== null && ino !== void 0 ? ino : 0); | ||
this.mode = this._convert(mode !== null && mode !== void 0 ? mode : 0o644 & S_IFREG); | ||
if ((this.mode & S_IFMT) == 0) { | ||
@@ -113,3 +114,3 @@ this.mode = (this.mode | this._convert(S_IFREG)); | ||
hasAccess(mode, context) { | ||
const creds = context?.credentials || credentials; | ||
const creds = (context === null || context === void 0 ? void 0 : context.credentials) || credentials; | ||
if (this.isSymbolicLink() || creds.euid === 0 || creds.egid === 0) | ||
@@ -172,12 +173,12 @@ return true; | ||
get atimeNs() { | ||
return BigInt(this.atimeMs) * 1000n; | ||
return BigInt(this.atimeMs) * n1000; | ||
} | ||
get mtimeNs() { | ||
return BigInt(this.mtimeMs) * 1000n; | ||
return BigInt(this.mtimeMs) * n1000; | ||
} | ||
get ctimeNs() { | ||
return BigInt(this.ctimeMs) * 1000n; | ||
return BigInt(this.ctimeMs) * n1000; | ||
} | ||
get birthtimeNs() { | ||
return BigInt(this.birthtimeMs) * 1000n; | ||
return BigInt(this.birthtimeMs) * n1000; | ||
} | ||
@@ -259,11 +260,11 @@ } | ||
/** Type of file system. */ | ||
this.type = 0x7a656e6673n; | ||
this.type = BigInt('0x7a656e6673'); | ||
/** Optimal transfer block size. */ | ||
this.bsize = 4096n; | ||
this.bsize = BigInt(4096); | ||
/** Total data blocks in file system. */ | ||
this.blocks = 0n; | ||
this.blocks = BigInt(0); | ||
/** Free blocks in file system. */ | ||
this.bfree = 0n; | ||
this.bfree = BigInt(0); | ||
/** Available blocks for unprivileged users */ | ||
this.bavail = 0n; | ||
this.bavail = BigInt(0); | ||
/** Total file nodes in file system. */ | ||
@@ -270,0 +271,0 @@ this.files = BigInt(size_max); |
@@ -81,3 +81,3 @@ import { randomHex } from 'utilium'; | ||
} | ||
throw new ErrnoError(Errno.EINVAL, 'Invalid mode: ' + mode?.toString()); | ||
throw new ErrnoError(Errno.EINVAL, 'Invalid mode: ' + (mode === null || mode === void 0 ? void 0 : mode.toString())); | ||
} | ||
@@ -124,3 +124,3 @@ /** | ||
return { | ||
encoding: typeof options == 'string' ? options : encoding ?? null, | ||
encoding: typeof options == 'string' ? options : encoding !== null && encoding !== void 0 ? encoding : null, | ||
flag, | ||
@@ -131,5 +131,5 @@ mode, | ||
return { | ||
encoding: typeof options?.encoding == 'string' ? options.encoding : encoding ?? null, | ||
flag: typeof options?.flag == 'string' ? options.flag : flag, | ||
mode: normalizeMode('mode' in options ? options?.mode : null, mode), | ||
encoding: typeof (options === null || options === void 0 ? void 0 : options.encoding) == 'string' ? options.encoding : encoding !== null && encoding !== void 0 ? encoding : null, | ||
flag: typeof (options === null || options === void 0 ? void 0 : options.flag) == 'string' ? options.flag : flag, | ||
mode: normalizeMode('mode' in options ? options === null || options === void 0 ? void 0 : options.mode : null, mode), | ||
}; | ||
@@ -136,0 +136,0 @@ } |
@@ -40,6 +40,6 @@ /* Shared eslint rules */ | ||
'@typescript-eslint/require-await': 'warn', | ||
'@typescript-eslint/no-unsafe-member-access': 'off', | ||
'@typescript-eslint/no-unsafe-argument': 'off', | ||
'@typescript-eslint/no-unsafe-assignment': 'off', | ||
'@typescript-eslint/no-unsafe-return': 'warn', | ||
'@typescript-eslint/no-unsafe-assignment': 'warn', | ||
'@typescript-eslint/no-unsafe-member-access': 'warn', | ||
'@typescript-eslint/no-unsafe-argument': 'warn', | ||
'@typescript-eslint/no-redundant-type-constituents': 'warn', | ||
@@ -55,5 +55,2 @@ '@typescript-eslint/no-unsafe-call': 'warn', | ||
rules: { | ||
'@typescript-eslint/no-unsafe-member-access': 'off', | ||
'@typescript-eslint/no-unsafe-argument': 'off', | ||
'@typescript-eslint/no-unsafe-assignment': 'off', | ||
'@typescript-eslint/no-floating-promises': 'off', | ||
@@ -60,0 +57,0 @@ '@typescript-eslint/no-explicit-any': 'off', |
{ | ||
"name": "@zenfs/core", | ||
"version": "1.6.10", | ||
"version": "1.6.11", | ||
"description": "A filesystem, anywhere", | ||
@@ -76,3 +76,4 @@ "funding": { | ||
"optionalDependencies": { | ||
"minimatch": "^9.0.3" | ||
"minimatch": "^9.0.3", | ||
"c8": "^10.1.2" | ||
}, | ||
@@ -82,3 +83,2 @@ "devDependencies": { | ||
"@types/eslint__js": "^8.42.3", | ||
"c8": "^10.1.2", | ||
"eslint": "^9.15.0", | ||
@@ -85,0 +85,0 @@ "globals": "^15.9.0", |
590634
10
134
14791
8