@struktoai/mirage-core
Version:
A Unified Virtual Filesystem For AI Agents
116 lines • 4.2 kB
JavaScript
import { OneDriveAccessor, OneDriveConfig } from "../../accessor/onedrive.js";
import { filesContaining } from "../../core/msgraph/search.js";
import { capacity as onedriveCapacity } from "../../core/onedrive/capacity.js";
import { driveLoc } from "../../core/onedrive/client.js";
import { copy } from "../../core/onedrive/copy.js";
import { create } from "../../core/onedrive/create.js";
import { buildDeltaHook } from "../../core/onedrive/events.js";
import { exists } from "../../core/onedrive/exists.js";
import { mkdir } from "../../core/onedrive/mkdir.js";
import { read } from "../../core/onedrive/read.js";
import { readdir } from "../../core/onedrive/readdir.js";
import { rename } from "../../core/onedrive/rename.js";
import { rmR } from "../../core/onedrive/rm.js";
import { rmdir } from "../../core/onedrive/rmdir.js";
import { stat, tree } from "../../core/onedrive/stat.js";
import { readStream } from "../../core/onedrive/stream.js";
import { truncate } from "../../core/onedrive/truncate.js";
import { unlink } from "../../core/onedrive/unlink.js";
import { write } from "../../core/onedrive/write.js";
import { VFSName } from "../../types.js";
import { BaseVFS } from "../base.js";
export class OneDriveVFS extends BaseVFS {
name = VFSName.ONEDRIVE;
cachesReads = true;
// Graph driveItems carry an exact byte `size` for every file in both
// listings and item gets; folders (including the root) report null with
// the aggregate storage number in extra.
sizesAlwaysKnown = true;
supportsSnapshot = true;
// stat and every read that can fill the cache stamp the item's cTag, the
// read taking it before the bytes, so the gate compares like with like.
readRevalidatable = true;
indexTtl = 86_400;
wholeWordSearch = true;
accessor;
config;
constructor(config) {
super();
this.config = config;
this.accessor = new OneDriveAccessor(config);
}
readsRanges = true;
readdir(path, handed) {
return readdir(this.accessor, path, handed?.limit);
}
read(path, _handed, offset = 0, size = null) {
if (offset === 0 && size === null)
return readStream(this.accessor, path);
return read(this.accessor, path, size === null ? { offset } : { offset, size });
}
stat(path) {
return stat(this.accessor, path);
}
exists(path) {
return exists(this.accessor, path);
}
readTree(path, handed) {
return tree(this.accessor, path, handed?.limit);
}
write(path, data, signal) {
return write(this.accessor, path, data, signal);
}
create(path) {
return create(this.accessor, path);
}
mkdir(path, parents = false) {
return mkdir(this.accessor, path, parents);
}
unlink(path) {
return unlink(this.accessor, path);
}
rmdir(path) {
return rmdir(this.accessor, path);
}
rmR(path) {
return rmR(this.accessor, path);
}
rename(src, dst) {
return rename(this.accessor, src, dst);
}
copy(src, dst) {
return copy(this.accessor, src, dst);
}
dirCopy(src, dst) {
return copy(this.accessor, src, dst);
}
truncate(path, length, noCreate = false) {
return truncate(this.accessor, path, length, noCreate);
}
/**
* Whether this VFS answers `name`; with no walk limit it reads every
* file rather than ask the service's search.
*/
supports(name) {
if (name === 'files_containing' && this.walkLimit < 0)
return false;
return super.supports(name);
}
filesContaining(path, text, opts) {
if (!opts.wholeWord || this.walkLimit < 0)
return Promise.resolve(null);
const config = this.accessor.config;
const scopes = [path].map((d) => [d, driveLoc(config, d.vfsPath)]);
return filesContaining(config, scopes, text);
}
capacity() {
return onedriveCapacity(this.accessor);
}
deltaHook() {
return buildDeltaHook(this.accessor);
}
getState() {
return this.configState(OneDriveConfig, this.config);
}
}
//# sourceMappingURL=onedrive.js.map