@struktoai/mirage-core
Version:
A Unified Virtual Filesystem For AI Agents
52 lines • 2.73 kB
TypeScript
export declare const SEPARATOR = "__";
/**
* Join an already-transformed label to its id inside NAME_MAX.
*
* The id and the suffix are what make the name *address* something, so they
* are spent first and never trimmed; the label takes whatever of the 255
* bytes is left. Trimming the id instead would leave a name that no longer
* resolves, and `parseIdName` splits on the last separator, so a shortened
* label still round-trips.
*
* Budgets in bytes, not characters: `sanitizeName` caps at 100 characters and
* `pathSafeName` does not cap at all, so a CJK display name reached 621 bytes
* against a 255-byte NAME_MAX and the filesystem refused the name outright.
*
* Takes the label already transformed because callers differ on the
* transform: most pass one name through `sanitizeName`, while Linear's team
* directory joins two sanitized parts with the separator itself --
* re-sanitizing that would collapse `__` to `_` and change the name's shape.
*/
export declare function fitIdName(label: string, resourceId: string, suffix?: string): string;
/**
* Name a file blob `<stem>__<id>.<ext>` after its first non-empty name.
*
* An empty name is a missing one, so the next candidate answers for it, and a
* blob with none is `file`. The extension is what follows the last dot only
* when both sides of that dot hold something and it holds no `/`: `photo.`,
* `.bashrc` and `1.2/notes` keep their whole spelling as the stem. The stem
* goes through `pathSafeName` and is the only part trimmed to fit NAME_MAX --
* the id and extension are what make the name resolve, so they are spent
* first.
*/
export declare function fileIdName(resourceId: string, ...names: (string | undefined)[]): string;
/**
* Build a `<name>__<id>` segment for VFS paths.
*
* Used by mounts that encode resource IDs in filenames for reverse lookups
* (Discord, Slack, gcal calendars, Linear, Trello). By default applies the
* full `sanitizeName` transform; set `pathSafe` to preserve the original
* spelling and only escape the path separator. Discord and Slack use
* `pathSafe` so display names stay readable.
*
* Pass `suffix` here rather than concatenating an extension afterwards, so it
* is counted against the NAME_MAX budget instead of pushing the name past it.
*/
export declare function makeIdName(displayName: string, resourceId: string, pathSafe?: boolean, suffix?: string): string;
/**
* Extract `[displayName, resourceId]` from `makeIdName` output, optionally
* stripping a file extension first. Throws when `name` doesn't end with
* `suffix` or doesn't contain `__`.
*/
export declare function parseIdName(name: string, suffix?: string): [string, string];
//# sourceMappingURL=naming.d.ts.map