Skip to content

Filesystem abstraction layer for the ArikaJS framework.

License

Notifications You must be signed in to change notification settings

ArikaJs/storage

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

11 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Arika Storage

@arikajs/storage is the filesystem abstraction layer for the ArikaJS framework.

It provides a clean, unified API to work with local and cloud-based storage systems using interchangeable drivers, designed for maximum developer experience but designed for Node.js and TypeScript.

This package allows ArikaJS applications to interact with files without caring where or how they are stored.


✨ Features

  • Multiple storage disks: Configure different storage locations
  • Driver-based filesystem architecture: Pluggable storage backends
  • Storage Extensibility: Register custom drivers via extend()
  • Middleware pipelines: Intercept operations via disk().middleware()
  • Local filesystem driver: Built-in support for local file storage (v1)
  • Unified file API: put, get, delete, exists, url, copy, move
  • File mutation API: append, prepend
  • Buffer, string, and stream support: Flexible content handling
  • Configuration-based disk resolution: Easy setup via config files
  • TypeScript-first: Full type safety with JavaScript compatibility
  • Designed for cloud drivers: Ready for S3, GCS, Azure (S3 shipped)

πŸ“¦ Installation

npm install @arikajs/storage
# or
yarn add @arikajs/storage
# or
pnpm add @arikajs/storage

πŸš€ Quick Start

Basic File Operations

import { Storage } from '@arikajs/storage';

// Write a file
await Storage.put('files/example.txt', 'Hello Arika');

// Read a file
const content = await Storage.get('files/example.txt');

// Delete a file
await Storage.delete('files/example.txt');

πŸ’½ Working with Disks

Arika Storage supports multiple disks, each backed by a driver.

// Use a specific disk
await Storage.disk('local').put('notes.txt', 'Hello');

// Check if file exists on a disk
const exists = await Storage.disk('public').exists('image.png');

βš™οΈ Configuration

Storage disks are defined in your application configuration:

export default {
  default: 'local',

  disks: {
    local: {
      driver: 'local',
      root: './storage/app'
    },

    public: {
      driver: 'local',
      root: './storage/public',
      url: '/storage'
    }
  }
};

πŸ“ Supported Drivers (v1)

Driver Status
Local filesystem βœ… Supported
Amazon S3 βœ… Supported
Google Cloud Storage βœ… Supported
Azure Blob Storage βœ… Supported

πŸ“š API Reference

Storage.put(path, contents)

Write contents to a file.

await Storage.put('file.txt', 'content');

Storage.get(path)

Read file contents.

const content = await Storage.get('file.txt');

Throws FileNotFoundException if the file does not exist.

Storage.exists(path)

Check if a file exists.

const exists = await Storage.exists('file.txt');

Storage.delete(path)

Delete a file.

await Storage.delete('file.txt');

Storage.copy(path, newPath)

Copy a file to a new location.

await Storage.copy('file.txt', 'backup.txt');

Storage.move(path, newPath)

Move a file to a new location.

await Storage.move('file.txt', 'archive.txt');

Storage.append(path, contents)

Append contents to a file.

await Storage.append('log.txt', 'New log entry');

Storage.prepend(path, contents)

Prepend contents to a file.

await Storage.prepend('log.txt', 'First entry');

Storage.url(path)

Get the public URL for a file.

const url = Storage.url('image.png');

Returns a public URL if supported by the disk.


πŸ— Architecture

storage/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ Contracts
β”‚   β”‚   └── Filesystem.ts
β”‚   β”œβ”€β”€ Drivers
β”‚   β”‚   β”œβ”€β”€ AzureDriver.ts
β”‚   β”‚   β”œβ”€β”€ GCSDriver.ts
β”‚   β”‚   β”œβ”€β”€ LocalDriver.ts
β”‚   β”‚   └── S3Driver.ts
β”‚   β”œβ”€β”€ Exceptions
β”‚   β”‚   └── FileNotFoundException.ts
β”‚   β”œβ”€β”€ Disk.ts
β”‚   β”œβ”€β”€ index.ts
β”‚   └── StorageManager.ts
β”œβ”€β”€ tests/
β”œβ”€β”€ package.json
β”œβ”€β”€ tsconfig.json
└── README.md

πŸ”Œ Extending Storage (Custom Drivers)

You can create your own storage driver:

import { Filesystem } from '@arikajs/storage';

class CustomDriver implements Filesystem {
  async put(path: string, contents: string | Buffer): Promise<void> {
    // Implementation
  }

  async get(path: string): Promise<Buffer> {
    // Implementation
  }

  async delete(path: string): Promise<void> {
    // Implementation
  }

  async exists(path: string): Promise<boolean> {
    // Implementation
  }

  url(path: string): string {
    // Implementation
  }
}

Register it inside StorageManager using the extend() method:

storage.extend('custom', (config) => new CustomDriver(config));

🚦 Storage Middleware

You can attach disk-level middleware to intercept any storage operations (e.g., logging every write, encrypting payloads on .put(), etc.).

storage.disk('local').middleware(async (data, next) => {
    if (data.operation === 'put') {
        console.log(`Writing file: ${data.path}`);
        // Optionally modify payload before saving!
        // data.contents = encrypt(data.contents);
    }
    return await next(data);
});

πŸ”— Integration with ArikaJS

@arikajs/storage integrates seamlessly with:

  • @arikajs/auth β†’ User uploads
  • @arikajs/mail β†’ Attachments
  • @arikajs/logging β†’ File logs
  • @arikajs/queue β†’ Temporary files
  • @arikajs/view β†’ Asset handling

πŸ§ͺ Testing

The storage layer is fully testable by mocking drivers or using temporary disks.


πŸ›£ Roadmap

  • S3 driver
  • GCS driver
  • Azure Blob driver
  • Streaming API
  • Temporary signed URLs
  • Disk-level middleware
  • File metadata support

πŸ“„ License

@arikajs/storage is open-source software licensed under the MIT License.


🧭 Philosophy

"Your application should care about files, not filesystems."

About

Filesystem abstraction layer for the ArikaJS framework.

Resources

License

Stars

Watchers

Forks

Packages

No packages published