UNPKG

@struktoai/mirage-core

Version:

A Unified Virtual Filesystem For AI Agents

45 lines • 2.15 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 { enotdir } from "../../errors/fs.js"; import { ancestors, norm } from "../../utils/path.js"; import { compareCodePoints } from "../../utils/sort.js"; import { listEntries } from "./client.js"; import { folderOf, kindsOf, lookupError } from "./dest.js"; import { backendPath } from "./path.js"; import { fileStat } from "./stat.js"; /** * A folder's rows from one listing, sorted by name. drive9 lists a missing * folder as an empty one, so only an empty listing asks what the path is. A * name that is both a file and a directory lists once, as the directory, as * it does on an object store. */ export async function readdir(accessor, path) { const listPath = path.pattern !== null ? path.dir : path; const key = norm(listPath.mountPath); const entries = await listEntries(accessor, backendPath(accessor.config, listPath)); if (entries.length === 0) { const kinds = await kindsOf(accessor, [...ancestors(key), key]); const found = folderOf(kinds, key); if (found === null) throw lookupError(kinds, listPath, key); if (!found.isDir) throw enotdir(listPath); return []; } const rows = new Map([...entries] .sort((a, b) => Number(a.isDir) - Number(b.isDir)) .map((entry) => [entry.name, fileStat(entry)])); return [...rows].sort(([a], [b]) => compareCodePoints(a, b)).map(([, row]) => row); } //# sourceMappingURL=readdir.js.map