@struktoai/mirage-core
Version:
A Unified Virtual Filesystem For AI Agents
86 lines • 4.39 kB
TypeScript
import { PathSpec } from '../../../../types.ts';
import type { Context } from '../../../config.ts';
import { type Repo } from './repo.ts';
/** What a remote publishes before anything is fetched. */
export interface Advertisement {
/** Every ref name and the object id it holds, `HEAD` included. */
readonly refs: Map<string, string>;
/** The commit each annotated tag peels to. */
readonly peeled: Map<string, string>;
/** The ref HEAD points at, null when detached or unsaid. */
readonly head: string | null;
}
/** Whether the receiver already holds an object. */
export type Has = (oid: string) => Promise<boolean>;
/** A remote a fetch or clone reads from. */
export interface Transport {
advertise(): Promise<Advertisement>;
fetchPack(wants: readonly string[], haves: readonly string[], has: Has): Promise<Uint8Array>;
}
/** One pkt-line: four hex digits of length, then the payload. */
export declare function pktLine(data: Uint8Array | string): Uint8Array;
/** Split a pkt-line stream, yielding null for each flush. */
export declare function pktLines(data: Uint8Array): Generator<Uint8Array | null>;
/** Read a protocol v0 ref advertisement. */
export declare function parseAdvertisement(lines: Iterable<Uint8Array | null>): Advertisement;
/** A remote's URL as git prints it: no credentials, no `.git`. */
export declare function displayUrl(url: string): string;
/**
* Every object reachable from `wants` that the other side lacks.
*
* Commits the other side has stop the walk; the trees of those boundary commits
* are what it already holds, so their contents are left out as upload-pack's
* edge does. Gitlinks name another repository and are never followed.
*/
export declare function missingObjects(repo: Repo, wants: readonly string[], has: Has): Promise<string[]>;
/** A repository inside the workspace, read through the dispatcher. */
export declare class LocalTransport implements Transport {
private readonly repo;
private readonly head;
constructor(repo: Repo, head: string | null);
/** The source's refs, as upload-pack would advertise them. */
advertise(): Promise<Advertisement>;
/** A pack of everything reachable from `wants` the receiver lacks. */
fetchPack(wants: readonly string[], _haves: readonly string[], has: Has): Promise<Uint8Array>;
}
/**
* A remote reached over git's smart HTTP protocol, version 0.
*
* The credentials a URL carried belong to its origin: when the first request
* is redirected to another one they are dropped, as git reads credentials again
* from the URL it was sent to. Configured headers go with every request, which
* is what git does with `http.extraHeader`.
*/
export declare class HttpTransport implements Transport {
private url;
private readonly headers;
private credentials;
private readonly configured;
/**
* @param url the repository URL, credentials stripped
* @param headers extra headers for every request
* @param credentials the Authorization header the URL's userinfo spelled,
* empty for none
*/
constructor(url: string, headers: Record<string, string>, credentials: Record<string, string>);
private request;
/** GET `info/refs` for upload-pack and read what it lists. */
advertise(): Promise<Advertisement>;
/** POST the wants and haves to upload-pack; return the pack. */
fetchPack(wants: readonly string[], haves: readonly string[]): Promise<Uint8Array>;
}
/** `http.extraHeader` values as a header table, later ones winning. */
export declare function extraHeaders(values: readonly string[]): Record<string, string>;
/**
* The transport a remote URL or workspace path names.
*
* `https://` and `http://` speak smart HTTP; a path, or a `file://` URL, is a
* repository inside the workspace reached through the dispatcher. Anything
* else names a remote helper mirage does not have, which git words the same
* way. `scoped` is an Authorization for the URL's origin when it carries no
* userinfo, dropped with it on a redirect elsewhere.
*/
export declare function openTransport(ctx: Context, url: string, start: PathSpec, headers: Record<string, string>, scoped?: Readonly<Record<string, string>>): Promise<Transport>;
/** Whether a remote names a path rather than a URL. */
export declare function isLocal(url: string): boolean;
//# sourceMappingURL=transport.d.ts.map