@struktoai/mirage-core
Version:
A Unified Virtual Filesystem For AI Agents
58 lines • 2.32 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 { CONTENT_HASH, RESULT_HEADER, REV } from "./constants.js";
/**
* A file's content token: its content_hash, or null. stat, readdir and read
* all stamp by this, so both sides of a `read: fresh` check are the same kind.
* server_modified is no token: Dropbox repeats it across same-size rewrites.
*/
export function tokenOf(value) {
return typeof value === 'string' && value !== '' ? value : null;
}
/** A looked-up entry's live tokens, null when it is no file. Mirrors Python's `live_of`. */
export function liveOf(entry) {
if (entry?.['.tag'] !== 'file')
return null;
return { content: tokenOf(entry[CONTENT_HASH]), native: tokenOf(entry[REV]) };
}
/**
* The content token a download's result metadata names: what `resultOf`
* parsed, or null. Mirrors Python's `result_token`.
*/
export function resultToken(result) {
return result === null ? null : tokenOf(result[CONTENT_HASH]);
}
/**
* The file metadata a download's `Dropbox-API-Result` carries, or null.
* Dropbox sends it on a full and on a ranged (206) download, so a read learns
* the file's token and name with no extra request. Mirrors Python's
* `result_of`.
*/
export function resultOf(raw) {
if (raw === null || raw === undefined || raw === '')
return null;
let result;
try {
result = JSON.parse(raw);
}
catch {
result = null;
}
if (typeof result !== 'object' || result === null || Array.isArray(result)) {
console.warn(`unreadable ${RESULT_HEADER} header: ${raw}`);
return null;
}
return result;
}
//# sourceMappingURL=fingerprint.js.map