s5-js/src/client.ts

97 lines
2.5 KiB
TypeScript
Raw Normal View History

2023-12-10 20:03:56 +00:00
import {
uploadFile,
uploadLargeFile,
uploadDirectory,
uploadDirectoryRequest,
uploadSmallFile,
uploadSmallFileRequest,
uploadLargeFileRequest,
2023-12-12 02:53:10 +00:00
uploadWebapp,
uploadWebappRequest,
} from "./methods/upload.js";
2023-12-11 04:33:55 +00:00
import {
2024-02-13 05:30:13 +00:00
downloadBlob,
2023-12-11 04:33:55 +00:00
downloadData,
downloadFile,
2024-02-13 05:30:13 +00:00
downloadProof,
2023-12-11 04:33:55 +00:00
getCidUrl,
getMetadata,
} from "./methods/download.js";
2023-12-10 20:03:56 +00:00
import { ensureUrl } from "./utils/url.js";
2023-12-10 20:03:56 +00:00
2023-12-12 03:44:43 +00:00
import {
createEntry,
getEntry,
2023-12-12 03:44:43 +00:00
publishEntry,
subscribeToEntry,
} from "./methods/registry.js";
import { CustomClientOptions } from "#utils/options.js";
import { throwValidationError } from "#utils/validation.js";
2023-12-10 20:03:56 +00:00
2024-03-16 15:44:32 +00:00
import { accountPins } from "./methods/account.js";
2023-12-10 20:03:56 +00:00
/**
* The S5 Client which can be used to access S5-net.
*/
export class S5Client {
// Upload
uploadFile = uploadFile;
uploadDirectory = uploadDirectory;
// Set methods (defined in other files).
2023-12-12 02:53:10 +00:00
uploadWebapp = uploadWebapp;
2023-12-10 20:03:56 +00:00
downloadFile = downloadFile;
2023-12-11 04:33:55 +00:00
downloadData = downloadData;
2024-02-13 05:30:13 +00:00
downloadBlob = downloadBlob;
downloadProof = downloadProof;
2023-12-10 20:03:56 +00:00
getCidUrl = getCidUrl;
getMetadata = getMetadata;
2023-12-11 02:06:43 +00:00
// Registry
subscribeToEntry = subscribeToEntry;
2023-12-12 03:26:42 +00:00
publishEntry = publishEntry;
2023-12-12 03:44:43 +00:00
createEntry = createEntry;
getEntry = getEntry;
2024-03-16 15:44:32 +00:00
accountPins = accountPins;
// Download
protected uploadSmallFile = uploadSmallFile;
protected uploadSmallFileRequest = uploadSmallFileRequest;
protected uploadLargeFile = uploadLargeFile;
protected uploadLargeFileRequest = uploadLargeFileRequest;
protected uploadDirectoryRequest = uploadDirectoryRequest;
protected uploadWebappRequest = uploadWebappRequest;
2023-12-11 02:06:43 +00:00
2023-12-10 20:03:56 +00:00
/**
* The S5 Client which can be used to access S5-net.
*
* @class
* @param [portalUrl] The initial portal URL to use to access S5, if specified. A request will be made to this URL to get the actual portal URL. To use the default portal while passing custom options, pass "".
2023-12-10 20:03:56 +00:00
* @param [customOptions] Configuration for the client.
*/
constructor(portalUrl: string, customOptions: CustomClientOptions = {}) {
if (!portalUrl) {
throwValidationError("portalUrl", portalUrl, "parameter", "string");
2023-12-10 20:03:56 +00:00
}
this._portalUrl = ensureUrl(portalUrl);
this._customOptions = customOptions;
2023-12-10 20:03:56 +00:00
}
private _customOptions: CustomClientOptions;
2023-12-10 20:03:56 +00:00
get customOptions(): CustomClientOptions {
return this._customOptions;
2023-12-10 20:03:56 +00:00
}
private _portalUrl: string;
2023-12-10 20:03:56 +00:00
get portalUrl(): string {
return this._portalUrl;
2023-12-10 20:03:56 +00:00
}
public static create(
portalUrl: string,
customOptions: CustomClientOptions = {},
) {
return new S5Client(portalUrl, customOptions);
2023-12-10 20:03:56 +00:00
}
}