@struktoai/mirage-core
Version:
A Unified Virtual Filesystem For AI Agents
56 lines • 2.33 kB
JavaScript
// ========= 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 { deleteCondition, nativeCondition } from "../../cache/context.js";
import { liftLost, lostCount, record, startOp } from "../../observe/context.js";
import { eisdir, enoent } from "../../errors/fs.js";
import { DropboxApiError } from "./client.js";
import { deletePath, getMetadata, refused } from "./api.js";
import { liveOf } from "./fingerprint.js";
import { checkPath, dropboxPathOf } from "./paths.js";
/**
* Delete a looked-up file, held to the version read, else the one found.
* Mirrors Python's `delete_resolved`.
*/
export async function deleteResolved(accessor, path, entry) {
const live = liveOf(entry);
const cond = await deleteCondition(path, live?.content ?? null);
const rev = await nativeCondition(path, cond, live, 'delete');
try {
await deletePath(accessor.tokenManager, dropboxPathOf(accessor, path), rev);
}
catch (err) {
throw (await refused(path, err, cond, rev)) ?? err;
}
}
export async function unlink(accessor, path) {
await checkPath(accessor, path);
const apiPath = dropboxPathOf(accessor, path);
let entry;
try {
entry = await getMetadata(accessor.tokenManager, apiPath);
}
catch (err) {
if (err instanceof DropboxApiError && err.status === 409)
throw enoent(path.virtual);
throw err;
}
if (entry['.tag'] === 'folder')
throw eisdir(path.virtual);
const timer = startOp();
const upto = lostCount();
await deleteResolved(accessor, path, entry);
record('unlink', path.virtual, 'dropbox', 0, timer);
liftLost(path, upto);
}
//# sourceMappingURL=unlink.js.map