UNPKG

@struktoai/mirage-core

Version:

A Unified Virtual Filesystem For AI Agents

51 lines • 2.29 kB
// ========= Copyright 2026 @ Strukto.AI All Rights Reserved. ========= // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // ========= Copyright 2026 @ Strukto.AI All Rights Reserved. ========= import { lookup } from "./api.js"; import { enoent } from "../../errors/fs.js"; import { rawPathOf } from "../../utils/key_prefix.js"; import { stripSlash } from "../../utils/slash.js"; /** Map a mount path to the Dropbox API path under the configured root. */ export function dropboxPathOf(accessor, path) { const key = stripSlash(rawPathOf(path)); return key === '' ? accessor.rootPath : `${accessor.rootPath}/${key}`; } /** * Whether Dropbox answered for `path` with a name in another case. * * Dropbox matches a path case-insensitively, a listing does not: a file stored * as `N` is not `n`. An answer without a name proves nothing, and calling it * absent would let a write go out over a file that is there. Mirrors Python's * `spelled_otherwise`. */ export function spelledOtherwise(path, entry) { const key = stripSlash(path.vfsPath); const named = entry?.name; return typeof named === 'string' && named !== key.slice(key.lastIndexOf('/') + 1); } /** Validate existing components below the configured root, never accepting case aliases. */ export async function checkPath(accessor, path) { const key = stripSlash(rawPathOf(path)); let at = accessor.rootPath; let entry = null; for (const part of key === '' ? [] : key.split('/')) { at = `${at}/${part}`; entry = await lookup(accessor.tokenManager, at); if (entry == null) return null; if (typeof entry.name === 'string' && entry.name !== part) throw enoent(path.virtual); } return entry; } //# sourceMappingURL=paths.js.map