observablehq-file-attachments
Version:
Library to handle ObservableHQ's file attachments more flexibly, and to support virtualizing them.
65 lines • 2.26 kB
TypeScript
/**
* Proxy wrapper for returned values.
*
* @module
*/
import { CACHED_METADATA, METADATA } from "./symbols";
import { IAFileAwait, JsonObject, Metadata, VFile } from "./types";
/**
* This accepts a `Promise`, and delegates its methods to the resolved result of the `Promise`.
*
* If the eventual result is null, the invoking the data access methods will return `undefined`.
*
* Use {@link AFileAwait.exists} to throw an {@link VirtualFileNotFound} error if the file is not found.
* ```javascript
* const data = FS.find('/nofile').exists.json();
* ```
*/
export declare class AFileAwait implements IAFileAwait {
#private;
/**
*
* @param target The `Promise` of a result.
* @param name The name of the file, if available.
*/
constructor(target: Promise<VFile | null>, name?: string);
url(): Promise<string | undefined>;
json(): Promise<JsonObject | undefined>;
blob(): Promise<Blob | undefined>;
text(): Promise<string | undefined>;
arrayBuffer(): Promise<ArrayBuffer | undefined>;
csv(): Promise<string | undefined>;
tsv(): Promise<string | undefined>;
/**
* @returns the name, if it was supplied on construction, or if
* the promise has resolved. Otherwise, returns `'(unresolved)'`;
*/
get name(): string;
/**
* Awaiting on this will yield the original result, including `null` if not found.
*/
get target(): Promise<VFile | null>;
/**
* Chaining method that throws an error if the file was not found.
* @returns The underlying file object.
*/
get exists(): AFileAwait;
[METADATA]: Metadata | undefined;
[CACHED_METADATA]: Metadata | undefined;
/**
* Preserve the class name across minification.
*/
[Symbol.toStringTag]: 'AFileAwait';
}
/**
* The error thrown when a file is not found in the virtual filesystem.
* This is only thrown by [.check()](#AFileAwait.check).
*/
export declare class VirtualFileNotFound extends Error {
constructor(message?: string);
/**
* Preserve the class name across minification.
*/
[Symbol.toStringTag]: 'VirtualFileNotFound';
}
//# sourceMappingURL=AFileAwait.d.ts.map