@codex-storage/sdk-js
Version:
Codex SDK to interact with the Codex decentralized storage network.
219 lines (210 loc) • 11.8 kB
TypeScript
import { F as FetchAuth, S as SafeValue, d as CodexDataItems, f as CodexNodeSpace, l as UploadStategy, U as UploadResponse, h as CodexNetworkDownload, j as CodexManifest, p as paths, o as components } from './types-C5Toly_l.js';
import * as v from 'valibot';
type CodexDataOptions = {
auth?: FetchAuth;
};
declare class CodexData {
readonly url: string;
readonly auth: FetchAuth;
constructor(url: string, options?: CodexDataOptions);
/**
* Lists manifest CIDs stored locally in node.
* TODO: remove the faker data part when the api is ready
*/
cids(): Promise<SafeValue<CodexDataItems>>;
/**
* Gets a summary of the storage space allocation of the node.
*/
space(): Promise<SafeValue<CodexNodeSpace>>;
/**
* Upload a file in a streaming manner.
* Once completed, the file is stored in the node and can be retrieved by any node in the network using the returned CID.
* XMLHttpRequest is used instead of fetch for this case, to obtain progress information.
* A callback onProgress can be passed to receive upload progress data information.
*/
upload(stategy: UploadStategy): UploadResponse;
/**
* Download a file from the local node in a streaming manner.
* If the file is not available locally, a 404 is returned.
*/
localDownload(cid: string): Promise<SafeValue<Response>>;
/**
* Download a file from the network to the local node if it's not available locally.
* Note: Download is performed async. Call can return before download is completed.
*/
networkDownload(cid: string): Promise<SafeValue<CodexNetworkDownload>>;
/**
* Download a file from the network in a streaming manner.
* If the file is not available locally, it will be retrieved from other nodes in the network if able.
*/
networkDownloadStream(cid: string): Promise<SafeValue<Response>>;
/**
* Download only the dataset manifest from the network to the local node
* if it's not available locally.
*/
fetchManifest(cid: string): Promise<SafeValue<CodexManifest>>;
}
type CodexSprTextResponse = paths["/spr"]["get"]["responses"][200]["content"]["text/plain"];
type CodexSprJsonResponse = paths["/spr"]["get"]["responses"][200]["content"]["application/json"];
type CodexSprContentType = "json" | "text";
type CodexSpr<T extends CodexSprContentType> = T extends "json" ? CodexSprJsonResponse : T extends "text" ? CodexSprTextResponse : never;
type CodexPeerIdTextResponse = paths["/peerid"]["get"]["responses"][200]["content"]["text/plain"];
type CodexPeerIdJsonResponse = paths["/peerid"]["get"]["responses"][200]["content"]["application/json"];
type CodexPeerIdContentType = "json" | "text";
type CodexPeerId<T extends CodexPeerIdContentType> = T extends "json" ? CodexPeerIdJsonResponse : T extends "text" ? CodexPeerIdTextResponse : never;
type CodexNodeOptions = {
auth?: FetchAuth;
};
declare class CodexNode {
readonly url: string;
readonly auth: FetchAuth;
constructor(url: string, options?: CodexNodeOptions);
/**
* Connect to a peer
*/
connect(peerId: string, addrs?: string[]): Promise<SafeValue<string>>;
/**
* Get Node's SPR
*/
spr(type?: CodexSprContentType): Promise<SafeValue<CodexSpr<CodexSprContentType>>>;
/**
* Get Node's PeerID
*/
peerId(type?: CodexPeerIdContentType): Promise<SafeValue<CodexPeerId<CodexPeerIdContentType>>>;
}
type CodexSlotResponse = paths["/sales/slots"]["get"]["responses"][200]["content"]["application/json"];
type CodexSlot = CodexSlotResponse;
type CodexSlotAgentResponse = paths["/sales/slots/{slotId}"]["get"]["responses"][200]["content"]["application/json"];
type CodexSlotAgent = CodexSlotAgentResponse;
type CodexAvailabilityResponse = paths["/sales/availability"]["get"]["responses"][200]["content"]["application/json"];
type CodexAvailabilityWithoutTypes = components["schemas"]["SalesAvailabilityREAD"];
type CodexAvailability = Omit<CodexAvailabilityWithoutTypes, "freeSize" | "totalSize" | "minPricePerBytePerSecond" | "duration" | "totalCollateral" | "totalRemainingCollateral"> & {
freeSize?: number;
totalSize: number;
duration: number;
minPricePerBytePerSecond: number;
totalCollateral: number;
totalRemainingCollateral: number;
};
type CodexAvailabilityCreateResponse = paths["/sales/availability"]["post"]["responses"][201]["content"]["application/json"];
type CodexAvailabilityCreateBody = Exclude<paths["/sales/availability"]["post"]["requestBody"], undefined>["content"]["application/json"];
type CodexAvailabilityPatchResponse = paths["/sales/availability/{id}"]["patch"]["responses"][204]["content"];
type CodexAvailabilityPatchBody = Exclude<paths["/sales/availability"]["post"]["requestBody"], undefined>["content"]["application/json"];
declare const CodexCreateAvailabilityInput: v.StrictObjectSchema<{
readonly totalSize: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, 1, undefined>]>;
readonly duration: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, 1, undefined>]>;
readonly minPricePerBytePerSecond: v.NumberSchema<undefined>;
readonly totalCollateral: v.NumberSchema<undefined>;
readonly enabled: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
readonly until: v.OptionalSchema<v.NumberSchema<undefined>, undefined>;
}, undefined>;
type CodexCreateAvailabilityInput = v.InferOutput<typeof CodexCreateAvailabilityInput>;
declare const CodexAvailabilityPatchInput: v.StrictObjectSchema<{
readonly id: v.StringSchema<undefined>;
readonly totalSize: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, 1, undefined>]>;
readonly duration: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, 1, undefined>]>;
readonly minPricePerBytePerSecond: v.NumberSchema<undefined>;
readonly totalCollateral: v.NumberSchema<undefined>;
readonly enabled: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
readonly until: v.OptionalSchema<v.NumberSchema<undefined>, undefined>;
}, undefined>;
type CodexAvailabilityPatchInput = v.InferOutput<typeof CodexAvailabilityPatchInput>;
type CodexReservationsResponse = paths["/sales/availability/{id}/reservations"]["get"]["responses"][200]["content"]["application/json"];
type CodexReservation = components["schemas"]["Reservation"];
type CodexPurchaseIdsResponse = paths["/storage/purchases"]["get"]["responses"][200]["content"]["application/json"];
type CodexPurchaseResponse = paths["/storage/purchases/{id}"]["get"]["responses"][200]["content"]["application/json"];
type CodexStorageAsk = Omit<components["schemas"]["StorageAsk"], "slotSize" | "duration" | "proofProbability" | "pricePerBytePerSecond"> & {
slotSize: number;
duration: number;
proofProbability: number;
pricePerBytePerSecond: number;
};
type CodexPurchaseWithoutTypes = components["schemas"]["Purchase"];
type CodexPurchase = Omit<components["schemas"]["Purchase"], "request"> & {
request?: Omit<components["schemas"]["StorageRequest"], "ask"> & {
ask: CodexStorageAsk;
};
};
type CodexStorageRequestResponse = paths["/storage/request/{cid}"]["post"]["responses"][200]["content"]["text/plain"];
type CodexStorageRequestCreateBody = Exclude<paths["/storage/request/{cid}"]["post"]["requestBody"], undefined>["content"]["application/json"];
declare const CodexCreateStorageRequestInput: v.StrictObjectSchema<{
readonly cid: v.StringSchema<undefined>;
readonly duration: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, 1, undefined>]>;
readonly pricePerBytePerSecond: v.NumberSchema<undefined>;
readonly proofProbability: v.NumberSchema<undefined>;
readonly nodes: v.OptionalSchema<v.NumberSchema<undefined>, 1>;
readonly tolerance: v.OptionalSchema<v.NumberSchema<undefined>, 0>;
readonly expiry: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, 1, undefined>]>;
readonly collateralPerByte: v.NumberSchema<undefined>;
}, undefined>;
type CodexCreateStorageRequestInput = v.InferOutput<typeof CodexCreateStorageRequestInput>;
type CodexMarketplaceOptions = {
auth?: FetchAuth;
};
declare class CodexMarketplace {
readonly url: string;
readonly auth: FetchAuth;
constructor(url: string, options?: CodexMarketplaceOptions);
/**
* Returns active slots
*/
activeSlots(): Promise<SafeValue<CodexSlot[]>>;
/**
* Returns active slot with id {slotId} for the host
*/
activeSlot(slotId: string): Promise<SafeValue<CodexSlotAgent>>;
private transformAvailability;
/**
* Returns storage that is for sale
*/
availabilities(): Promise<SafeValue<CodexAvailability[]>>;
/**
* Offers storage for sale
*/
createAvailability(input: CodexCreateAvailabilityInput): Promise<SafeValue<CodexAvailability>>;
/**
* The new parameters will be only considered for new requests.
* Existing Requests linked to this Availability will continue as is.
*/
updateAvailability(input: CodexAvailabilityPatchInput): Promise<SafeValue<"">>;
/**
* Return's list of Reservations for ongoing Storage Requests that the node hosts.
*/
reservations(availabilityId: string): Promise<SafeValue<CodexReservation[]>>;
/**
* Returns list of purchase IDs
*/
purchaseIds(): Promise<SafeValue<CodexPurchaseIdsResponse>>;
private transformPurchase;
purchases(): Promise<SafeValue<CodexPurchase[]>>;
/**
* Returns purchase details
*/
purchaseDetail(purchaseId: string): Promise<SafeValue<CodexPurchase>>;
/**
* Creates a new request for storage.
*/
createStorageRequest(input: CodexCreateStorageRequestInput): Promise<SafeValue<string>>;
}
type CodexLogLevelResponse = paths["/debug/chronicles/loglevel"]["post"]["responses"][200]["content"];
type CodexLogLevel = paths["/debug/chronicles/loglevel"]["post"]["parameters"]["query"]["level"];
declare const CodexLogLevelInput: v.PicklistSchema<["TRACE", "DEBUG", "INFO", "NOTICE", "WARN", "ERROR", "FATAL"], undefined>;
type CodexInfoResponse = paths["/debug/info"]["get"]["responses"][200]["content"]["application/json"];
type CodexDebugInfo = CodexInfoResponse;
type CodexDebugOptions = {
auth?: FetchAuth;
};
declare class CodexDebug {
readonly url: string;
readonly auth: FetchAuth;
constructor(url: string, options?: CodexDebugOptions);
/**
* Set log level at run time
*/
setLogLevel(level: CodexLogLevel): Promise<SafeValue<string>>;
/**
* Gets node information
*/
info(): Promise<SafeValue<CodexDebugInfo>>;
}
export { type CodexLogLevelResponse as A, type CodexLogLevel as B, CodexMarketplace as C, CodexLogLevelInput as D, type CodexInfoResponse as E, type CodexDebugInfo as F, CodexData as a, CodexNode as b, CodexDebug as c, type CodexSlotResponse as d, type CodexSlot as e, type CodexSlotAgentResponse as f, type CodexSlotAgent as g, type CodexAvailabilityResponse as h, type CodexAvailabilityWithoutTypes as i, type CodexAvailability as j, type CodexAvailabilityCreateResponse as k, type CodexAvailabilityCreateBody as l, CodexCreateAvailabilityInput as m, type CodexAvailabilityPatchResponse as n, type CodexAvailabilityPatchBody as o, CodexAvailabilityPatchInput as p, type CodexReservationsResponse as q, type CodexReservation as r, type CodexPurchaseIdsResponse as s, type CodexPurchaseResponse as t, type CodexStorageAsk as u, type CodexPurchaseWithoutTypes as v, type CodexPurchase as w, type CodexStorageRequestResponse as x, type CodexStorageRequestCreateBody as y, CodexCreateStorageRequestInput as z };