Skip to content

[NO ISSUE] docs: update Storage azion lib usage #1727

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
116 changes: 74 additions & 42 deletions src/content/docs/en/pages/devtools/azion-lib/usage/storage.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ The `createClient` method has the following **parameters** and **return value**:

| Parameter | Type | Description |
|-----------|------|-------------|
| `config` | `Partial<{ token: string; options?: OptionsParams }>` | Configuration options for the Storage client. |
| `config` | `Partial<{ token: string; options?: AzionClientOptions }>` | Configuration options for the Storage client. |

**Returns**:

Expand All @@ -82,7 +82,7 @@ import { createBucket } from 'azion/storage';
import type { AzionStorageResponse, AzionBucket } from 'azion/storage';
const { data, error }: AzionStorageResponse<AzionBucket> = await createBucket({
name: 'my-new-bucket',
edge_access: 'public',
edge_access: 'read_write',
});
if (data) {
console.log(`Bucket created with name: ${data.name}`);
Expand All @@ -96,8 +96,8 @@ if (data) {
| Parameter | Type | Description |
|-----------|------|-------------|
| `name` | `string` | The name of the new bucket. |
| `edge_access` | `string` | The `edge access` configuration for the bucket. |
| `options?` | `AzionClientOptions` | Optional parameters for the request. |
| `edge_access` | [`EdgeAccessType`](#edgeaccesstype) | The `edge access` configuration for the bucket. |
| `options?` | [`AzionClientOptions`](#azionclientoptions) | Optional parameters for the request. |

**Returns**:

Expand Down Expand Up @@ -127,7 +127,7 @@ if (data) {
| Parameter | Type | Description |
|-----------|------|-------------|
| `name` | `string` | The name of the bucket to be deleted. |
| `debug?` | `boolean` | Enables debug mode for detailed logging. |
| `options?` | [`AzionClientOptions`](#azionclientoptions) | Optional parameters for the request. |

**Returns**:

Expand Down Expand Up @@ -158,10 +158,8 @@ if (buckets) {

| Parameter | Type | Description |
|-----------|------|-------------|
| `options?` | `AzionBucketCollectionOptions` | Optional parameters for filtering and pagination. |
| `page?` | `number` | The page number for pagination. |
| `page_size?` | `number` | The number of items per page. |
| `debug?` | `boolean` | Enables debug mode for detailed logging. |
| `params?` | [`AzionBucketCollectionParams`](#azionbucketcollectionparams) | Parameters for filtering and pagination. |
| `options?` | [`AzionClientOptions`](#azionclientoptions) | Optional parameters for the request. |

**Returns**:

Expand Down Expand Up @@ -191,7 +189,7 @@ if (bucket) {
| Parameter | Type | Description |
|-----------|------|-------------|
| `name` | `string` | The name of the bucket to be retrieved. |
| `debug?` | `boolean` | Enables debug mode for detailed logging. |
| `options?` | [`AzionClientOptions`](#azionclientoptions) | Optional parameters for the request. |

**Returns**:

Expand All @@ -210,7 +208,7 @@ import { updateBucket, AzionBucket, AzionStorageResponse } from 'azion/storage';

const { data: updatedBucket, error }: AzionStorageResponse<AzionBucket> | null = await updateBucket({
name: 'my-bucket',
edge_access: 'private',
edge_access: 'read_write',
});
if (updatedBucket) {
console.log(`Bucket updated: ${updatedBucket.name}`);
Expand All @@ -224,8 +222,8 @@ if (updatedBucket) {
| Parameter | Type | Description |
|-----------|------|-------------|
| `name` | `string` | The name of the bucket to be updated. |
| `edge_access` | `string` | The new `edge access` configuration for the bucket. |
| `debug?` | `boolean` | Enables debug mode for detailed logging. |
| `edge_access` | [`EdgeAccessType`](#edgeaccesstype) | The new `edge access` configuration for the bucket. |
| `options?` |[`AzionClientOptions`](#azionclientoptions) | Optional parameters for the request. |

**Returns**:

Expand All @@ -243,9 +241,9 @@ Example:
import { createObject, AzionBucketObject, AzionStorageResponse } from 'azion/storage';

const { data: newObject, error }: AzionStorageResponse<AzionBucketObject> = await createObject({
bucketName: 'my-bucket',
bucket: 'my-bucket',
key: 'new-file.txt',
file: 'File content',
content: 'File content',
});
if (newObject) {
console.log(`Object created with key: ${newObject.key}`);
Expand All @@ -259,10 +257,10 @@ if (newObject) {

| Parameter | Type | Description |
|-------------|----------|-----------------------------------------------|
| `bucketName` | `string` | The name of the bucket to create the object in. |
| `objectKey` | `string` | Key (name) of the object to be created. |
| `file` | `string` | The content of the file to be uploaded. |
| `debug?` | `boolean`| Enables debug mode for detailed logging. |
| `bucket` | `string` | The name of the bucket to create the object in.|
| `key` | `string` | Key (name) of the object to be created.|
| `content` | `string` | The content of the file to be uploaded.|
| `options?` | [`AzionClientOptions`](#azionclientoptions) | Optional parameters for the request. |

**Returns**:

Expand All @@ -280,7 +278,7 @@ Example:
import { getObjectByKey, AzionBucketObject, AzionStorageResponse } from 'azion/storage';

const { data: object, error }: AzionStorageResponse<AzionBucketObject> = await getObjectByKey({
bucketName: 'my-bucket',
bucket: 'my-bucket',
key: 'file.txt',
});
if (object) {
Expand All @@ -294,9 +292,9 @@ if (object) {

| Parameter | Type | Description |
|-----------|------|-------------|
| `bucketName` | `string` | The name of the bucket containing the object. |
| `objectKey` | `string` | The key of the object to be retrieved. |
| `debug?` | `boolean` | Enables debug mode for detailed logging. |
| `bucket` | `string` | The name of the bucket containing the object. |
| `key` | `string` | The key of the object to be retrieved. |
| `options?` | [`AzionClientOptions`](#azionclientoptions) | Optional parameters for the request. |

**Returns**:

Expand All @@ -314,7 +312,7 @@ Example:
import { getObjects, AzionBucketObject, AzionStorageResponse } from 'azion/storage';

const { data: objectResult, error }: AzionStorageResponse<AzionBucketObjects> = await getObjects({
bucketName: 'my-bucket',
bucket: 'my-bucket',
});
if (objectResult) {
console.log(`Retrieved ${objectResult.count} objects from the bucket`);
Expand All @@ -327,8 +325,9 @@ if (objectResult) {

| Parameter | Type | Description |
|-----------|------|-------------|
| `bucketName` | `string` | The name of the bucket to retrieve objects from. |
| `debug?` | `boolean` | Enables debug mode for detailed logging. |
| `bucket` | `string` | The name of the bucket to retrieve objects from. |
| `params?` | [`AzionObjectCollectionParams`](#azionobjectcollectionparams) | Parameters for filtering and pagination. |
| `options?` | [`AzionClientOptions`](#azionclientoptions) | Optional parameters for the request. |

**Returns**:

Expand All @@ -346,9 +345,9 @@ Example:
import { updateObject, AzionBucketObject } from 'azion/storage';

const { data: updatedObject, error }: AzionStorageResponse<AzionBucketObject> = await updateObject({
bucketName: 'my-bucket',
bucket: 'my-bucket',
key: 'file.txt',
file: 'Updated content',
content: 'Updated content',
});
if (updatedObject) {
console.log(`Object updated: ${updatedObject.key}`);
Expand All @@ -362,10 +361,10 @@ if (updatedObject) {

| Parameter | Type | Description |
|-----------|------|-------------|
| `bucketName` | `string` | The name of the bucket containing the object. |
| `objectKey` | `string` | The key of the object to be updated. |
| `file` | `string` | The new content of the file. |
| `debug?` | `boolean` | Enables debug mode for detailed logging. |
| `bucket` | `string` | The name of the bucket containing the object. |
| `key` | `string` | The key of the object to be updated. |
| `content` | `string` | The new content of the file. |
| `options?` | [`AzionClientOptions`](#azionclientoptions) | Optional parameters for the request. |

**Returns**:

Expand All @@ -377,13 +376,13 @@ if (updatedObject) {

Deletes an object from a specific bucket.

Example:
Example:

```typescript
import { deleteObject, AzionDeletedBucketObject, AzionStorageResponse } from 'azion/storage';

const { data: result, error }: AzionStorageResponse<AzionDeletedBucketObject> = await deleteObject({
bucketName: 'my-bucket',
bucket: 'my-bucket',
key: 'file.txt',
});
if (result) {
Expand All @@ -397,9 +396,9 @@ if (result) {

| Parameter | Type | Description |
|-----------|------|-------------|
| `bucketName` | `string` | The name of the bucket containing the object. |
| `objectKey` | `string` | The key of the object to be deleted. |
| `debug?` | `boolean` | Enables debug mode for detailed logging. |
| `bucket` | `string` | The name of the bucket containing the object. |
| `key` | `string` | The key of the object to be deleted. |
| `options?` | [`AzionClientOptions`](#azionclientoptions) | Optional parameters for the request. |

**Returns**:

Expand All @@ -413,14 +412,47 @@ if (result) {

These are the types used by the **Storage** library and its methods:

### `ClientConfig`
### AzionBucketCollectionParams

Parameters for filtering and pagination when retrieving a collection of buckets.

| Parameter | Type | Description |
|-----------|------|-------------|
| `page?` | `number` | The page number for pagination. |
| `page_size?` | `number` | The number of items per page. |

### `AzionObjectCollectionParams`

| Parameter | Type | Description |
|-----------|------|-------------|
| `max_object_count?` | `number` | The max number of items per request. |

### `EdgeAccessType`

The type of access control for the bucket.

```typescript
'read_only' | 'read_write' | 'restricted'
```

### `AzionClientOptions`

Configuration options for the Storage client.

| Parameter | Type | Description |
|-----------|------|-------------|
| `token?` | `string` | Your Azion API token. |
| `debug?` | `boolean` | Enables debug mode for detailed logging. |
| `force?` | `boolean` | Force the operation even if it might be destructive. |
| `env?` | [`AzionEnvironment`](#azionenvironment) | Environment to use (dev, stage, prod). |
| `external?` | `boolean` | Force using external REST API instead of built-in runtime API. |

### AzionEnvironment

The environment in which the client operates.

```typescript
'development' | 'staging' | 'production'
```

### `StorageClient`

Expand All @@ -429,8 +461,8 @@ An object with methods to interact with Storage.
| Method | Parameters | Return Type |
|--------|------------|--------------|
| `getBuckets` | `options?: BucketCollectionOptions` | `Promise<AzionStorageResponse<AzionBucketCollection>>` |
| `createBucket` | `name: string, edge_access: string` | `Promise<AzionStorageResponse<AzionBucket>>` |
| `updateBucket` | `name: string, edge_access: string` | `Promise<AzionStorageResponse<AzionBucket>>` |
| `createBucket` | `name: string, edge_access: EdgeAccessType` | `Promise<AzionStorageResponse<AzionBucket>>` |
| `updateBucket` | `name: string, edge_access: EdgeAccessType` | `Promise<AzionStorageResponse<AzionBucket>>` |
| `deleteBucket` | `name: string` | `Promise<AzionStorageResponse<AzionDeletedBucket>>` |
| `getBucket` | `name: string` | `Promise<AzionStorageResponse<AzionBucket>>` |

Expand All @@ -450,7 +482,7 @@ The bucket object.
| Property | Type | Description |
|----------|------|-------------|
| `name` | `string` | The name of the bucket. |
| `edge_access` | `string` (optional) | The `edge access` of the bucket. |
| `edge_access` | [`EdgeAccessType`](#edgeaccesstype) | The `edge access` of the bucket. |
| `state` | `'executed' \| 'pending'` (optional) | The state of the bucket. |
| `getObjects` | `() => Promise<AzionStorageResponse<AzionBucketObjects>>` (optional) | A method to get all objects in the bucket. |
| `getObjectByKey` | `(objectKey: string) => Promise<AzionStorageResponse<AzionBucketObject>>` (optional) | A method to get an object by its key. |
Expand Down
Loading