@struktoai/mirage-core
Version:
A Unified Virtual Filesystem For AI Agents
54 lines • 2.68 kB
TypeScript
import { ReadPolicy, type ReadSpec } from '../../types.ts';
import type { IndexConfig } from '../../cache/index/config.ts';
import type { BaseVFS } from '../../vfs/base.ts';
/**
* Coerce a declared read policy and bound into a ReadSpec.
*
* Coercion only: an unknown name is refused here, but whether the resolved
* policy is one this mount's backend can honour is `checkReadCapability`'s
* question. The two are split the way Python's `fuse/backend.py` splits
* `resolve_backend` from `require_kernel_backend`, so the config loader and the
* mount entry point each run exactly one of them and a refusal is computed once.
*
* Missing means bounded at the default bound, everywhere: an absent `read:`
* in YAML, `undefined` here, and the `Mount` options default all resolve to
* the same thing.
*
* @throws if the policy name is not a known one, or the bound is not a
* positive whole number of seconds.
*/
/**
* Coerce one declared policy name to its `ReadPolicy`, or refuse it.
*
* Split out so the mount entry point can run it on a spec that never passed
* through `resolveReadSpec`: `ReadPolicy` is a plain string-const object, so
* a runtime `ReadSpec` carrying `'FRESH'` or `'banana'` matches no `===` in
* the verdict and would mount and then read as `bounded` everywhere. Absent
* (`undefined`, `null`, `''`) means bounded, which is what YAML's bare
* `read:` parses as. Idempotent on a member. Mirrors Python's
* `coerce_read_policy`.
*
* @throws if the value is not a known policy name.
*/
export declare function coerceReadPolicy(value: unknown): ReadPolicy;
export declare function resolveReadSpec(policy: unknown, ttl: unknown): ReadSpec;
/**
* Refuse a read policy this mount's backend cannot honour.
*
* The rules are ordered, and the order is the answer to two questions that
* collide on a disk mount: whether the gate can fire at all, and whether the
* token behind it is worth comparing. A backend that does not cache reads is
* answered by the first and never reaches the second.
*
* A policy that cannot act must say so. Degrading `fresh` to `bounded` on a
* backend that cannot revalidate is the silent downgrade this whole policy
* exists to remove, so it is a refusal at mount time rather than a warning at
* read time.
*
* @param index the index config the mount will be built from, which is the
* listing cache fresh would check; undefined for a RAM store at the
* driver's `indexTtl`
* @throws if the backend cannot honour the declared policy.
*/
export declare function checkReadCapability(prefix: string, vfs: BaseVFS, spec: ReadSpec, index?: IndexConfig): void;
//# sourceMappingURL=read_policy.d.ts.map