logos-storage-js/src/data/data.throwable.ts
2025-05-30 16:55:33 +02:00

34 lines
1.1 KiB
TypeScript

import { CodexData } from "./data";
import type { UploadStrategy } from "./types";
import { type FetchAuth } from "../fetch-safe/fetch-safe";
import { Throwable } from "../throwable/throwable";
type CodexDataThrowableOptions = {
auth?: FetchAuth;
};
export class CodexDataThrowable {
readonly data: CodexData;
constructor(url: string, options?: CodexDataThrowableOptions) {
this.data = new CodexData(url, options);
}
cids = () => Throwable.from(this.data.cids());
space = () => Throwable.from(this.data.space());
upload = (strategy: UploadStrategy) => {
const { result, abort } = this.data.upload(strategy);
return {
result: Throwable.from(result),
abort,
};
};
localDownload = (cid: string) => Throwable.from(this.data.localDownload(cid));
networkDownload = (cid: string) =>
Throwable.from(this.data.networkDownload(cid));
networkDownloadStream = (cid: string) =>
Throwable.from(this.data.networkDownloadStream(cid));
fetchManifest = (cid: string) => Throwable.from(this.data.fetchManifest(cid));
delete = (cid: string) => Throwable.from(this.data.delete(cid));
}