
TinyCloudStorage
TinyCloudStorage provides decentralized storage functionality through TinyCloud's storage protocol. This class implements both the IStorage and ITinyCloudStorage interfaces.
import { TinyCloudStorage } from '@tinycloudlabs/web-sdk';
Description
TinyCloudStorage allows for storing, retrieving, and managing data in a decentralized way. It handles authentication and session management for secure data operations.
Constructor
constructor(config: any, userAuth: IUserAuthorization)
Creates a new instance of the TinyCloudStorage class.
Parameters:
config
- Configuration options for TinyCloud storagehosts
- Optional array of TinyCloud storage host endpointsprefix
- Optional prefix to use for all storage operationsautoCreateNew
- Whether to automatically create a new storage instance if one doesn't exist
userAuth
- User authorization interface for authentication
Properties
Name | Type | Description |
---|---|---|
namespace | string | The namespace identifier for TinyCloud storage. Default: 'tinycloud' |
prefix | string | The prefix used for all storage operations. |
storageId | string | undefined | The user's storage identifier. |
domain | string | undefined | The domain to display in the SIWE message. |
Methods
get
async get(key: string, options?: IStorageGetOptions): Promise<Response>
Retrieves data from storage by key.
Parameters:
key
- The key to retrieveoptions
- Optional configuration for the get operation
Returns: A Promise containing the response with the data
Example:
const response = await storage.get('myData');
console.log(response.data);
put
async put(key: string, value: any, options?: IStoragePutOptions): Promise<Response>
Stores data in storage with the specified key.
Parameters:
key
- The key to store the data undervalue
- The value to storeoptions
- Optional configuration for the put operation
Returns: A Promise containing the response from the storage operation
Example:
const data = { name: 'Example', value: 42 };
await storage.put('myData', data);
list
async list(options?: IStorageListOptions): Promise<Response>
Lists keys in storage, optionally filtered by path.
Parameters:
options
- Configuration options for the list operationprefix
- Custom prefix to use instead of the defaultpath
- Sub-path to list within the prefixremovePrefix
- Whether to remove the prefix from the returned keysrequest
- Additional request options
Returns: A Promise containing the response with the list of keys
Example:
const response = await storage.list({
path: 'folder',
removePrefix: true
});
console.log(response.data); // List of keys
delete
async delete(key: string, options?: IStorageDeleteOptions): Promise<Response>
Deletes the data stored under the specified key.
Parameters:
key
- The key to deleteoptions
- Optional configuration for the delete operation
Returns: A Promise containing the response from the delete operation
Example:
await storage.delete('myData');
deleteAll
async deleteAll(prefix?: string): Promise<Response[]>
Deletes all data under a specific prefix.
Parameters:
prefix
- Optional sub-prefix to delete data under
Returns: A Promise containing an array of responses from the delete operations
Example:
await storage.deleteAll('folder');
delegate
async delegate(params: DelegateParams): Promise<DelegateResponse>
Creates a delegation to allow another user to access specific resources.
Parameters:
params
- Parameters for the delegationtarget
- The target file or folder path you are sharingdelegateDID
- The DID of the key you are delegating toactions
- The actions you are authorizing the delegate to dostatement
- Optional statement in the authentication message
Returns: A Promise containing the delegation response with authentication message and signature
generateSharingLink
async generateSharingLink(path: string, params?: any): Promise<string>
Generates a sharing link for a specific file or folder.
Parameters:
path
- The path to the file or folder to shareparams
- Optional additional parameters
Returns: A Promise containing the encoded sharing link as a string
retrieveSharingLink
async retrieveSharingLink(encodedShare: string): Promise<Response>
Retrieves the data from a sharing link.
Parameters:
encodedShare
- The encoded sharing link
Returns: A Promise containing the response with the shared data