Metorial Object Storage Client

0.2.5 · active · verified Tue Apr 21

The `object-storage-client` package provides a TypeScript and JavaScript client library for programmatic interaction with the Metorial Object Storage Service. It offers a comprehensive, promise-based API for managing buckets and objects, including creation, listing, uploading, downloading, and deletion. The current stable version, 0.2.5, indicates it is in early development and pre-1.0 stability, meaning minor versions might introduce breaking changes. Its key differentiators include strong TypeScript support, a direct interface to the Metorial Object Storage backend (which itself supports multiple storage backends like local filesystem, AWS S3, Google Cloud Storage, and Azure Blob Storage), and a straightforward API for asynchronous operations. This client is specifically designed for the Metorial ecosystem, which aims to connect AI agents to various tools and services.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates the full lifecycle of object storage operations: creating a bucket, uploading a text file, downloading it, listing objects, and finally deleting both the object and the bucket. It also includes basic error handling for API-specific and generic errors.

import { ObjectStorageClient, ObjectStorageError } from 'object-storage-client';

const client = new ObjectStorageClient('http://localhost:8080');

async function runObjectStorageDemo() {
  try {
    // Create a bucket
    const bucketName = 'my-unique-test-bucket-' + Date.now();
    console.log(`Attempting to create bucket: ${bucketName}`);
    const bucket = await client.createBucket(bucketName);
    console.log(`Created bucket: ${bucket.name}`);

    // Upload an object
    const data = Buffer.from('Hello, Object Storage World!');
    const objectKey = 'hello.txt';
    console.log(`Uploading object '${objectKey}' to '${bucketName}'`);
    const obj = await client.putObject(
      bucketName,
      objectKey,
      data,
      'text/plain',
      { author: 'AI-Agent' }
    );
    console.log(`Uploaded object: ${obj.key} (ETag: ${obj.etag})`);

    // Download an object
    console.log(`Downloading object '${objectKey}' from '${bucketName}'`);
    const objData = await client.getObject(bucketName, objectKey);
    console.log(`Downloaded ${objData.data.length} bytes. Content: ${objData.data.toString()}`);

    // List objects
    console.log(`Listing objects in '${bucketName}'`);
    const objects = await client.listObjects(bucketName);
    for (const item of objects) {
      console.log(`- ${item.key}: ${item.size} bytes`);
    }

    // Delete object
    console.log(`Deleting object '${objectKey}' from '${bucketName}'`);
    await client.deleteObject(bucketName, objectKey);
    console.log('Object deleted.');

    // Delete bucket
    console.log(`Deleting bucket: ${bucketName}`);
    await client.deleteBucket(bucketName);
    console.log('Bucket deleted.');

  } catch (error) {
    if (error instanceof ObjectStorageError) {
      console.error(`Object Storage API Error: Status ${error.statusCode}, Message: ${error.message}`);
    } else if (error instanceof Error) {
      console.error(`Generic Error: ${error.message}`);
    } else {
      console.error('An unknown error occurred:', error);
    }
  }
}

runObjectStorageDemo();

view raw JSON →