Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
349 changes: 349 additions & 0 deletions docs/sdks/tigris/api-reference.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,349 @@
# Tigris Storage API Reference

## Configuration

### TigrisStorageConfig

The configuration object for Tigris Storage operations.

```typescript
type TigrisStorageConfig = {
bucket?: string;
accessKeyId?: string;
secretAccessKey?: string;
endpoint?: string;
};
```

**Properties:**

- `bucket` (optional): The storage bucket name
- `accessKeyId` (optional): Access key ID for authentication
- `secretAccessKey` (optional): Secret access key for authentication
- `endpoint` (optional): Custom endpoint URL

### TigrisStorageResponse

A generic response wrapper for all Tigris Storage operations. All the functions
return a `TigrisStorageResponse` object. If there is an error, the `error`
property will be set. If there is a successful response, the `data` property
will be set.

```typescript
type TigrisStorageResponse<T, E = unknown> = {
data?: T;
error?: E;
};
```

**Type Parameters:**

- `T`: The type of successful response data
- `E`: The type of error (defaults to `unknown`)

**Properties:**

- `data` (optional): The response data on success
- `error` (optional): Error information on failure

## Functions

### get()

Retrieves an object from storage with support for different return formats.

```typescript
// String format
function get(
path: string,
format: "string",
options?: GetOptions,
): Promise<TigrisStorageResponse<string, Error>>;

// File format
function get(
path: string,
format: "file",
options?: GetOptions,
): Promise<TigrisStorageResponse<File, Error>>;

// Stream format
function get(
path: string,
format: "stream",
options?: GetOptions,
): Promise<TigrisStorageResponse<ReadableStream, Error>>;
```

**Parameters:**

- `path`: The path to the object in storage
- `format`: The desired return format (`'string'`, `'file'`, or `'stream'`)
- `options` (optional): Additional options for the get operation

**Returns:** Promise resolving to a `TigrisStorageResponse` with the requested
data type.

#### GetOptions

```typescript
type GetOptions = {
config?: TigrisStorageConfig;
contentDisposition?: "attachment" | "inline";
contentType?: string;
encoding?: string;
};
```

**Properties:**

- `config` (optional): Tigris storage configuration
- `contentDisposition` (optional): How the content should be presented
(`'attachment'` or `'inline'`)
- `contentType` (optional): MIME type of the content
- `encoding` (optional): Character encoding for the content

### list()

Lists objects in the storage bucket with pagination support.

```typescript
function list(
options?: ListOptions,
): Promise<TigrisStorageResponse<ListResponse, Error>>;
```

**Parameters:**

- `options` (optional): Options for listing objects

**Returns:** Promise resolving to a `TigrisStorageResponse` containing the list
of items.

#### ListOptions

```typescript
type ListOptions = {
limit?: number;
paginationToken?: string;
config?: TigrisStorageConfig;
};
```

**Properties:**

- `limit` (optional): Maximum number of items to return
- `paginationToken` (optional): Token for continuing pagination
- `config` (optional): Tigris storage configuration

#### ListResponse

```typescript
type ListResponse = {
items: Item[];
paginationToken: string | undefined;
hasMore: boolean;
};
```

**Properties:**

- `items`: Array of storage items
- `paginationToken`: Token for the next page (undefined if no more pages)
- `hasMore`: Boolean indicating if more items are available

#### Item

```typescript
type Item = {
id: string;
name: string;
size: number;
lastModified: Date;
};
```

**Properties:**

- `id`: Unique identifier for the item
- `name`: Name of the item
- `size`: Size of the item in bytes
- `lastModified`: Date when the item was last modified

### head()

Retrieves metadata about an object without downloading its content.

```typescript
function head(
path: string,
options?: HeadOptions,
): Promise<TigrisStorageResponse<HeadResponse, Error> | undefined>;
```

**Parameters:**

- `path`: The path to the object in storage
- `options` (optional): Options for the head operation

**Returns:** Promise resolving to a `TigrisStorageResponse` with object
metadata, or `undefined`.

#### HeadOptions

```typescript
type HeadOptions = {
config?: TigrisStorageConfig;
};
```

**Properties:**

- `config` (optional): Tigris storage configuration

#### HeadResponse

```typescript
type HeadResponse = {
contentDisposition: string;
contentType: string;
modified: Date;
path: string;
size: number;
url: string;
};
```

**Properties:**

- `contentDisposition`: Content disposition header value
- `contentType`: MIME type of the object
- `modified`: Date when the object was last modified
- `path`: Path of the object in storage
- `size`: Size of the object in bytes
- `url`: URL to access the object

### put()

Uploads data to storage.

```typescript
function put(
path: string,
data: string | ReadableStream | Blob | Buffer,
options?: PutOptions,
): Promise<TigrisStorageResponse<PutResponse, Error>>;
```

**Parameters:**

- `path`: The destination path in storage
- `data`: The data to upload (string, ReadableStream, Blob, or Buffer)
- `options` (optional): Options for the put operation

**Returns:** Promise resolving to a `TigrisStorageResponse` with upload details.

#### PutOptions

```typescript
type PutOptions = {
access?: "public" | "private";
addRandomSuffix?: boolean;
allowOverwrite?: boolean;
contentType?: string;
contentDisposition?: "attachment" | "inline";
multipart?: boolean;
abortController?: AbortController;
onUploadProgress?: PutOnUploadProgress;
config?: TigrisStorageConfig;
};
```

**Properties:**

- `access` (optional): Access level for the uploaded object (`'public'` or
`'private'`)
- `addRandomSuffix` (optional): Whether to add a random suffix to the path
- `allowOverwrite` (optional): Whether to allow overwriting existing objects,
defaults to `true`
- `contentType` (optional): MIME type of the content
- `contentDisposition` (optional): How the content should be presented
- `multipart` (optional): Whether to use multipart upload
- `abortController` (optional): Controller to abort the upload
- `onUploadProgress` (optional): Callback function for upload progress
- `config` (optional): Tigris storage configuration

#### PutOnUploadProgress

```typescript
type PutOnUploadProgress = ({
loaded,
total,
percentage,
}: {
loaded: number;
total: number;
percentage: number;
}) => void;
```

Callback function that receives upload progress information.

**Parameters:**

- `loaded`: Number of bytes uploaded
- `total`: Total number of bytes to upload
- `percentage`: Upload progress as a percentage

#### PutResponse

```typescript
type PutResponse = {
contentDisposition: string | undefined;
contentType: string | undefined;
modified: Date;
path: string;
size: number;
url: string;
};
```

**Properties:**

- `contentDisposition`: Content disposition header value (may be undefined)
- `contentType`: MIME type of the uploaded object (may be undefined)
- `modified`: Date when the object was uploaded/modified
- `path`: Path where the object was stored
- `size`: Size of the uploaded object in bytes
- `url`: URL to access the uploaded object

### remove()

Deletes an object from storage.

```typescript
function remove(
path: string,
options?: RemoveOptions,
): Promise<TigrisStorageResponse<void, Error> | void>;
```

**Parameters:**

- `path`: The path to the object to delete
- `options` (optional): Options for the remove operation

**Returns:** Promise resolving to a `TigrisStorageResponse` with void data, or
`void`.

#### RemoveOptions

```typescript
type RemoveOptions = {
config?: TigrisStorageConfig;
};
```

**Properties:**

- `config` (optional): Tigris storage configuration
Loading